Hello,
I am trying to validate and print installed version of "packages" on target hosts but seems code is broken somewhere, someone please help.
---
- name: Package installation using variables
hosts: dev
vars:
packages:
- httpd
- php
- mod_ssl
- mod_php
tasks:
- name: Installing "{{ packages }}"
yum:
name: "{{ packages }}"
state: present
- name: Validating if "{{ packages }}" installed
yum:
list: "{{ item }}"
with_items:
- "{{ packages }}"
register: package_status
- name: Checking package status
debug:
var: package_status.results
Tried also
debug:
msg: "{{ item.name }}-{{ item.version }} is {{ item.yumstate }}"
loop: "{{ package_status.results | selectattr('yumstate', 'equalto', 'installed') | list }}"
but is failing with below error
fatal: [node1]: FAILED! => {"msg": "'dict object' has no attribute 'yumstate'"}
How about the following to get you started?
---
- name: Package installation using variables
hosts: rhel7
vars:
packages:
- httpd
- nginx
tasks:
- name: Ensure package facts are gathered
package_facts:
- name: Check whether our packages are installed
debug:
msg: "{{ ansible_facts.packages[item], omit }}"
loop: "{{ packages }}"
- name: Display packages not installed
debug:
msg: "{{ item }} is not installed"
when: item not in ansible_facts.packages
loop: "{{ packages }}"
How about the following to get you started?
---
- name: Package installation using variables
hosts: rhel7
vars:
packages:
- httpd
- nginx
tasks:
- name: Ensure package facts are gathered
package_facts:
- name: Check whether our packages are installed
debug:
msg: "{{ ansible_facts.packages[item], omit }}"
loop: "{{ packages }}"
- name: Display packages not installed
debug:
msg: "{{ item }} is not installed"
when: item not in ansible_facts.packages
loop: "{{ packages }}"
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.