Software >> Automation >> Ansible >> Modules >> yum >> Examples

 

yum


## DOCUMENTATION

online help: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html
offline help: ansible-doc yum   (run this command on the ansible control node)


## PLAYBOOK

---
- name: ansible yum module - example 1
  hosts: all
  become: True
  tasks:
  - name: Install httpd package
    yum:
       name: httpd
       state: present
  - name: List the package
    yum:
       list: httpd
  - name: Use shell rpm command to check install date
    shell: rpm -q httpd --last
    register: results1
  - debug: var=results1.stdout_lines


## OUTPUT

PLAY [ansible yum module - example 1] ****************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************
ok: [rhel6_int]
ok: [rhel7_int]

TASK [Install httpd package] *************************************************************************************************************
changed: [rhel6_int]
changed: [rhel7_int]

TASK [List the package] ******************************************************************************************************************
ok: [rhel7_int]
ok: [rhel6_int]

TASK [Use shell rpm command to check install date] ***************************************************************************************
changed: [rhel7_int]
changed: [rhel6_int]

TASK [debug] *****************************************************************************************************************************
ok: [rhel6_int] => {
    "results1.stdout_lines": [
        "httpd-2.2.15-69.el6.x86_64                    Tue 26 Oct 2021 06:13:38 PM +08"
    ]
}
ok: [rhel7_int] => {
    "results1.stdout_lines": [
        "httpd-2.4.6-97.el7_9.1.x86_64                 Tue 26 Oct 2021 06:13:53 PM +08"
    ]
}

PLAY RECAP *******************************************************************************************************************************
rhel6_int                  : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
rhel7_int                  : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0