---

- 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









On Wednesday, January 29, 2020 at 7:35:42 PM UTC+5:30, Pawan Kumar wrote:
>
> Hi Team,
>
> I am able to extract the selected list of installed rpms using ansible 
> "shell" module ,But when I tried using "yum" module ,it's no success . 
> Your help would be appreciated . 
>
> The playbook which is running with "shell" module & it's output is as 
> follows ---
>
>
> Playbook---
>
> ---
> - hosts: localhost
>   tasks:
>     - name: Create a list
>       set_fact:
>         package_list:
>           - zlib
>           - parted
>           - gawk
>
>     - name: Display Lists
>       debug:
>         msg:
>          - "{{ package_list }}"
>
>
>     - name: ensure a list of packages installed
>       shell: rpm -qa "{{ item }}"
>       with_items: "{{ package_list }}"
>       register: ensure_list
>       args:
>         warn: false
>
>
>  
>     - name: show results values from ensure_list & filtering one of the 
> key attribute called 'stdout'
>       debug:
>         msg: "{{ ensure_list.results | map(attribute='stdout')|list }}"
>
>
>
>
>
> ================================================Output 
> =======================
>
>
> PLAY [localhost] 
> ********************************************************************************************************************************************
>
> TASK [Gathering Facts] 
> **************************************************************************************************************************************
> ok: [localhost]
>
> TASK [Create a list] 
> ****************************************************************************************************************************************
> ok: [localhost]
>
> TASK [Display Lists] 
> ****************************************************************************************************************************************
> ok: [localhost] => {
>     "msg": [
>         [
>             "zlib",
>             "parted",
>             "gawk"
>         ]
>     ]
> }
>
> TASK [ensure a list of packages installed] 
> ******************************************************************************************************************
> changed: [localhost] => (item=zlib)
> changed: [localhost] => (item=parted)
> changed: [localhost] => (item=gawk)
>
>
> TASK [show results values from ensure_list] 
> *****************************************************************************************************************
> ok: [localhost] => {
>     "msg": [
>         "zlib-1.2.7-18.el7.x86_64",
>         "parted-3.1-31.el7.x86_64",
>         "gawk-4.0.2-4.el7_3.1.x86_64"
>     ]
> }
>
> PLAY RECAP 
> **************************************************************************************************************************************************
> localhost                  : ok=6    changed=1    unreachable=0    
> failed=0    skipped=0    rescued=0    ignored=0
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6f134c38-977b-4ff8-8aa1-f90fc9d3f0c3%40googlegroups.com.

Reply via email to