---
- hosts: localhost
tasks:
- name: Create a list
set_fact:
package_list:
- zlib
- strace
- gawk
- name: Display Lists
debug:
msg:
- "{{ package_list }}"
- name: Create an empty list variable
set_fact:
list1: []
- name: Append string to ECE node list
set_fact:
list1: "{{ list1 + [ item ] }}"
with_items:
- "{{ package_list }}"
- name: ensure a list of packages installed
yum:
list: "{{ item }}"
with_items: "{{ list1 }}"
register: ensure_list
- name: Debug the list of installed rpms
debug:
msg: "{{ ensure_list }}"
- name: Conditionally print things if not installed
set_fact:
list_desired: "{{ ensure_list.results | map(attribute='results') | list }}"
when: ensure_list.results is defined and ensure_list.results != ''
- name: Extract teh dEsired data of rpm version and state
debug:
msg: "{{ list_desired | selectattr('yumstate','equalto','installed') | map(attribute='envra') | list }}"
PLAY [localhost] ****************************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************************
ok: [localhost]
TASK [Create a list] ************************************************************************************************************************************************************************
ok: [localhost]
TASK [Display Lists] ************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
[
"zlib",
"strace",
"gawk"
]
]
}
TASK [Create an empty list variable] ********************************************************************************************************************************************************
ok: [localhost]
TASK [Append string to ECE node list] *******************************************************************************************************************************************************
ok: [localhost] => (item=zlib)
ok: [localhost] => (item=strace)
ok: [localhost] => (item=gawk)
TASK [ensure a list of packages installed] **************************************************************************************************************************************************
ok: [localhost] => (item=zlib)
ok: [localhost] => (item=strace)
ok: [localhost] => (item=gawk)
TASK [Debug the list of installed rpms] *****************************************************************************************************************************************************
ok: [localhost] => {
"msg": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"allow_downgrade": false,
"autoremove": false,
"bugfix": false,
"conf_file": null,
"disable_excludes": null,
"disable_gpg_check": false,
"disable_plugin": [],
"disablerepo": [],
"download_dir": null,
"download_only": false,
"enable_plugin": [],
"enablerepo": [],
"exclude": [],
"install_repoquery": true,
"install_weak_deps": true,
"installroot": "/",
"list": "zlib",
"lock_timeout": 30,
"name": [],
"releasever": null,
"security": false,
"skip_broken": false,
"state": null,
"update_cache": false,
"update_only": false,
"use_backend": "auto",
"validate_certs": true
}
},
"item": "zlib",
"results": [
{
"arch": "i686",
"envra": "0:zlib-1.2.7-18.el7.i686",
"epoch": "0",
"name": "zlib",
"release": "18.el7",
"repo": "base",
"version": "1.2.7",
"yumstate": "available"
},
{
"arch": "x86_64",
"envra": "0:zlib-1.2.7-18.el7.x86_64",
"epoch": "0",
"name": "zlib",
"release": "18.el7",
"repo": "base",
"version": "1.2.7",
"yumstate": "available"
},
{
"arch": "x86_64",
"envra": "0:zlib-1.2.7-18.el7.x86_64",
"epoch": "0",
"name": "zlib",
"release": "18.el7",
"repo": "installed",
"version": "1.2.7",
"yumstate": "installed"
}
]
},
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"allow_downgrade": false,
"autoremove": false,
"bugfix": false,
"conf_file": null,
"disable_excludes": null,
"disable_gpg_check": false,
"disable_plugin": [],
"disablerepo": [],
"download_dir": null,
"download_only": false,
"enable_plugin": [],
"enablerepo": [],
"exclude": [],
"install_repoquery": true,
"install_weak_deps": true,
"installroot": "/",
"list": "strace",
"lock_timeout": 30,
"name": [],
"releasever": null,
"security": false,
"skip_broken": false,
"state": null,
"update_cache": false,
"update_only": false,
"use_backend": "auto",
"validate_certs": true
}
},
"item": "strace",
"results": [
{
"arch": "x86_64",
"envra": "0:strace-4.12-9.el7.x86_64",
"epoch": "0",
"name": "strace",
"release": "9.el7",
"repo": "base",
"version": "4.12",
"yumstate": "available"
},
{
"arch": "x86_64",
"envra": "0:strace-4.12-9.el7.x86_64",
"epoch": "0",
"name": "strace",
"release": "9.el7",
"repo": "installed",
"version": "4.12",
"yumstate": "installed"
}
]
},
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"allow_downgrade": false,
"autoremove": false,
"bugfix": false,
"conf_file": null,
"disable_excludes": null,
"disable_gpg_check": false,
"disable_plugin": [],
"disablerepo": [],
"download_dir": null,
"download_only": false,
"enable_plugin": [],
"enablerepo": [],
"exclude": [],
"install_repoquery": true,
"install_weak_deps": true,
"installroot": "/",
"list": "gawk",
"lock_timeout": 30,
"name": [],
"releasever": null,
"security": false,
"skip_broken": false,
"state": null,
"update_cache": false,
"update_only": false,
"use_backend": "auto",
"validate_certs": true
}
},
"item": "gawk",
"results": [
{
"arch": "x86_64",
"envra": "0:gawk-4.0.2-4.el7_3.1.x86_64",
"epoch": "0",
"name": "gawk",
"release": "4.el7_3.1",
"repo": "base",
"version": "4.0.2",
"yumstate": "available"
},
{
"arch": "x86_64",
"envra": "0:gawk-4.0.2-4.el7_3.1.x86_64",
"epoch": "0",
"name": "gawk",
"release": "4.el7_3.1",
"repo": "installed",
"version": "4.0.2",
"yumstate": "installed"
}
]
}
]
}
}
TASK [Conditionally print things if not installed] ******************************************************************************************************************************************
ok: [localhost]
TASK [Extract teh dEsired data of rpm version and state] ************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'list object' has no attribute 'yumstate'\n\nThe error appears to be in '/opt/tmo_iam/ansible_python27/.venv/rpm_package_raka.yml': line 43, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Extract teh dEsired data of rpm version and state\n ^ here\n"}
PLAY RECAP **********************************************************************************************************************************************************************************
localhost : ok=8 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0