Skip to content

Commit

Permalink
Make redhat_packages and virt use json_query instead of Python item a…
Browse files Browse the repository at this point in the history
…ccess

This lets the playbook continue when tasks fail.
  • Loading branch information
Noah Lavine committed Jan 25, 2018
1 parent 1c9637e commit 8ea3ef3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions roles/redhat_packages/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- name: set fact whether red hat rpms are installed or not
set_fact:
redhat_packages_gpg_is_redhat: '{{ redhat_packages_gpg_is_redhat["stdout_lines"][0] == "Y" }}'
redhat_packages_gpg_is_redhat: '{{ (redhat_packages_gpg_is_redhat | json_query("stdout_lines[0]")) == "Y" }}'

- name: gather the number of all installed red hat packages filtered by gpg keys
raw: rpm -qa --qf "%{SIGPGP:pgpsig}\n" | grep 'Key ID 199e2f91fd431d51\|Key ID 5326810137017186\|Key ID 45689c882fa658e0\|Key ID 219180cddb42a60e\|Key ID 7514f77d8366b0d9\|Key ID 45689c882fa658e0' | wc -l
Expand All @@ -18,7 +18,7 @@

- name: set fact of number of installed red hat packages filtered by gpg keys
set_fact:
redhat_packages_gpg_num_rh_packages: "{{ redhat_packages_gpg_num_rh_packages['stdout_lines'][0] }}"
redhat_packages_gpg_num_rh_packages: '{{ redhat_packages_gpg_num_rh_packages | json_query("stdout_lines[0]") }}'

- name: gather total number of installed packages
raw: rpm -qa | wc -l
Expand All @@ -28,7 +28,7 @@

- name: set fact of number of all installed rpm packages
set_fact:
redhat_packages_gpg_num_installed_packages: "{{ redhat_packages_all_count['stdout_lines'][0] }}"
redhat_packages_gpg_num_installed_packages: '{{ redhat_packages_all_count | json_query("stdout_lines[0]") }}'

- name: gather the last installed red hat package filtered by gpg keys
raw: rpm -qa --qf "%{INSTALLTIME} %{SIGPGP:pgpsig} |%{NAME}-%{VERSION} Installed:%{INSTALLTIME:date}\n" | grep 'Key ID 199e2f91fd431d51\|Key ID 5326810137017186\|Key ID 45689c882fa658e0\|Key ID 219180cddb42a60e\|Key ID 7514f77d8366b0d9\|Key ID 45689c882fa658e0' | sort -nr | head -n 1 | cut -d"|" -f2
Expand All @@ -39,7 +39,7 @@

- name: set fact of last installed rh package filtered by gpg key
set_fact:
redhat_packages_gpg_last_installed: "{{ redhat_packages_gpg_last_installed['stdout_lines'][0] }}"
redhat_packages_gpg_last_installed: '{{ redhat_packages_gpg_last_installed | json_query("stdout_lines[0]") }}'
when:
internal_have_rpm and redhat_packages_gpg_is_redhat

Expand All @@ -52,7 +52,7 @@

- name: set fact of last built rh package filtered by gpg key
set_fact:
redhat_packages_gpg_last_built: "{{ redhat_packages_gpg_last_built['stdout_lines'][0] }}"
redhat_packages_gpg_last_built: '{{ redhat_packages_gpg_last_built | json_query("stdout_lines[0]") }}'
when:
internal_have_rpm and redhat_packages_gpg_is_redhat

Expand All @@ -63,5 +63,5 @@

- name: extract result value for redhat-packages.certs
set_fact:
redhat_packages_certs: "{{ redhat_packages_certs_cmd['stdout'] | trim | default('error') }}"
redhat_packages_certs: '{{ redhat_packages_certs_cmd | json_query("stdout") | trim | default("error") }}'
when: '"stdout" in redhat_packages_certs_cmd'
16 changes: 8 additions & 8 deletions roles/virt/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@

- name: set virt.virt fact due to internal_cpu_model_name_kvm
set_fact: virt_virt="virt-guest"
when: 'internal_cpu_model_name_kvm["stdout_lines"][0] == "Y"'
when: '(internal_cpu_model_name_kvm | json_query("stdout_lines[0]")) == "Y"'

- name: set virt.type fact due to internal_cpu_model_name_kvm
set_fact: virt_type="kvm"
when: 'internal_cpu_model_name_kvm["stdout_lines"][0] == "Y"'
when: '(internal_cpu_model_name_kvm | json_query("stdout_lines[0]")) == "Y"'

- name: set virt.virt fact due to internal_sys_manu_vmware
set_fact: virt_virt="virt-guest"
Expand Down Expand Up @@ -152,19 +152,19 @@

- name: set virt.virt fact due to kvm
set_fact: virt_virt="virt-host"
when: 'internal_kvm_found["stdout_lines"][0] == "Y"'
when: '(internal_kvm_found | json_query("stdout_lines[0]")) == "Y"'

- name: set virt.type fact due to kvm
set_fact: virt_type="kvm"
when: 'internal_kvm_found["stdout_lines"][0] == "Y"'
when: '(internal_kvm_found | json_query("stdout_lines[0]")) == "Y"'

- name: set virt.virt fact due to privcmd
set_fact: virt_virt="virt-guest"
when: 'internal_privcmd_found["stdout_lines"][0] == "Y"'
when: '(internal_privcmd_found | json_query("stdout_lines[0]")) == "Y"'

- name: set virt.type fact due to privcmd
set_fact: virt_type="xen"
when: 'internal_privcmd_found["stdout_lines"][0] == "Y"'
when: '(internal_privcmd_found | json_query("stdout_lines[0]")) == "Y"'

- name: gather virt.num_guests fact
raw: virsh -c qemu:///system --readonly list --all | wc -l
Expand All @@ -173,7 +173,7 @@
when: 'internal_have_virsh'

- name: extract output virt.num_guests fact
set_fact: virt_num_guests="{{ virt_num_guests['stdout_lines'][0] if internal_have_virsh else None }}"
set_fact: virt_num_guests="{{ (virt_num_guests | json_query('stdout_lines[0]')) if internal_have_virsh else None }}"

- name: gather virt.num_running_guests fact
raw: virsh -c qemu:///system --readonly list --uuid | wc -l
Expand All @@ -182,4 +182,4 @@
when: 'internal_have_virsh'

- name: extract output virt.num_running_guests fact
set_fact: virt_num_running_guests="{{ internal_virt_num_running_guests['stdout_lines'][0] if internal_have_virsh else None }}"
set_fact: virt_num_running_guests="{{ (internal_virt_num_running_guests | json_query('stdout_lines[0]')) if internal_have_virsh else None }}"

0 comments on commit 8ea3ef3

Please sign in to comment.