I have to parse the output of the following command:
mongo --eval \"db.isMaster()\"
which gives output as follows:
There are quite a bit of helpful filters in Ansible.
Try: when: (output_text.stdout | from_json).ismaster
Brother Coder, honestly I got a better Method, because for 3 weeks I just could not parse it with ansible filters as it was to complicated and never worked. I just curled the FILE and used JQ parser with regex. The only thing that is required is that JQ PARSER has to be installed on the server:
To do it with ANSIBLE:
name: set-fact1 set_fact: claims1: "{{ apiaccountclaims.stdout }}"
name: Enter service tdiapiaccountclaims shell: sudo /usr/share/jbossas/bin/jboss-cli.sh -c --command='/system-property=tdigi.api.uri.edge.account.claims:add(value={{ claims1 }})'
Here is the playbook:
hosts: "{{ hosts | default('all') }}" become: true
vars_prompt: - name: "envid" prompt: "Please put env ID"
tasks:
- name: Get json file
shell: curl --output file.json -k -O https://example.tp.com/services/getMasterExtract.php?env_id={{envid}}&product=all&du=all&format=json&resolved=true
args:
chdir: /tmp/
- name: get value from file
shell: cat file.json | jq '.globals.environments.{{envid}}."legacy-claimcenter-hostname"' | sed 's/"//g'
args:
chdir: /tmp/
register: tdiapiaccountclaims
- name: set-fact1
set_fact:
claims1: "{{ apiaccountclaims.stdout }}"
- name: copy command file
copy:
src: "cli/systemprops2-2.cli"
dest: "/opt/jboss/profiles/{{jboss_profile}}/configuration/"
- name: backup standalone-full.xml
shell: cp "/opt/jboss/profiles/{{jboss_profile}}/configuration/standalone-full.xml" "/opt/jboss/profiles/{{jboss_profile}}/configuration/standalone-full.xml.backup.old"
- name: Delete Configs in file of standalone-full.xml
shell: sudo /usr/share/jbossas/bin/jboss-cli.sh -c --file=systemprops2-2.cli
args:
chdir: /opt/jboss/profiles/{{ jboss_profile }}/configuration
register: delvar
- name: Enter service tdiapiaccountclaims
shell: sudo /usr/share/jbossas/bin/jboss-cli.sh -c --command='/system-property=tdigi.api.uri.edge.account.claims:add(value={{ claims1 }})'