AnsiblePlaybooksUpdating the OS

Updating the operating system

Creating the playbook

Executed:

aadmin@uvm0:~/code/it-wiz/devops/ansible/projects/playbooks$ touch update_os.yml

Brought update_os.yml to the following form:

- name: Update operating system
  hosts: all
  tasks:
    - name: Update APT package cache
      apt:
        update_cache: yes

    - name: Upgrade all packages
      apt:
        upgrade: dist
        
    - name: Autoclean APT
      apt:
        autoclean: yes
        
    - name: Autoremove unnecessary packages
      apt:
        autoremove: yes

Equivalent Bash commands

root@uvm26:~# apt update && apt upgrade -y && apt autoclean && apt autoremove
root@uvm27:~# apt update && apt upgrade -y && apt autoclean && apt autoremove

Execution of the playbook

Executed:

aadmin@uvm0:~/code/it-wiz/devops/ansible/projects$ ansible-playbook playbooks/update_os.yml --ask-vault-pass

Details

    aadmin@uvm0:~/code/it-wiz/devops/ansible/projects$ ansible-playbook playbooks/update_os.yml --ask-vault-pass
    Vault password: <typed the vault password>
 
    PLAY [all] *******************************************************************************************************
 
    TASK [Gathering Facts] *******************************************************************************************
    ok: [uvm27]
    ok: [uvm26]
 
    TASK [Update APT package cache] **********************************************************************************
    changed: [uvm27]
    changed: [uvm26]
 
    TASK [Upgrade all packages] **************************************************************************************
    ok: [uvm26]
    changed: [uvm27]
 
    TASK [Autoclean APT] *********************************************************************************************
    ok: [uvm27]
    ok: [uvm26]
 
    TASK [Autoremove unnecessary packages] ***************************************************************************
    ok: [uvm27]
    changed: [uvm26]
 
    PLAY RECAP *******************************************************************************************************
    uvm26                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
    uvm27                      : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Result

The APT packages got updated.