1

i need to check more than 100 servers for the snapd package, but I don't like the output at all. I searched all day for different options without luck. Attached is the output of ansible-playbook. Any hints guys? enter image description here

---
 - hosts: centos
   become: true
   tasks:
    - name: Check Hostname
      command: /usr/bin/hostname

    - name: Check for package if is installed
      yum:
        list: snapd
      register: result

For checking the package version I tried with the following playbook but Ansible doesn't like the syntax:

---
 - hosts: test2
   become: true
   tasks:
    - name: Check Hostname
      command: /usr/bin/hostname

    - name: Check for package if is installed
      yum:
        list: snapd
      register: package_name_version

    - name: set package version
      set_fact:
        package_name_version: "{{ package_name_version.results|selectattr('yumstate','equalto','installed')|map(attribute='version')|list|first }}"

Thanks, Juls

2
  • 1
    I simple way would be to do ansible -i <inventory> <target group, lets' say some CentOS systems> -m shell -a "rpm -qa | grep <package name>"; that would display a list consisting of server name and package version.
    – 13dimitar
    Feb 19 '19 at 11:28
  • 1
    @13dimitar you should put that ad-hoc play into an answer :-)
    – simbo1905
    Feb 19 '19 at 17:49
1

A simple way would be to do:

ansible -i <inventory> <target group, lets' say some CentOS systems> -m shell -a "rpm -qa | grep <package name>"

That would display a list consisting of server name and package version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.