Script - Actualizar un Servidor Linux

Para actualizar un servidor (o grupo de servidores) añada lo siguiente a un script YML/YAML.

---
- hosts: linuxservers proxmoxservers
remote_user: ansible
become: yes
tasks:
    - name: 'update'
    apt:
        update_cache: yes
    - name: 'Install aptitude'
    apt:
        name: aptitude
        update_cache: yes
#       register: OUT
#    - name: Debug OUT
#     debug: msg={{ OUT.stdout_lines}}
    - name: 'upgrade'
    apt:
        name: "*"
        state: latest
#       register: OUT
#    - name: Debug OUT
#     debug: msg={{ OUT.stdout_lines}}
    - name: 'dist-upgrade'
    apt:
        upgrade: dist
#       register: OUT
#    - name: Debug OUT
#     debug: msg={{ OUT.stdout_lines}}
    - name: 'autoremove'
    apt:
        autoremove: yes
#       register: OUT
#    - name: Debug OUT
#     debug: msg={{ OUT.stdout_lines}}
    - name: 'autoclean'
    apt:
        autoclean: yes
        upgrade: dist
#       register: OUT
#    - name: Debug OUT
#     debug: msg={{ OUT.stdout_lines}}
    - name: 'check if reboot needed'
    stat: path=/var/run/reboot-required
    register: reboot_required_file
    - name: Rebooting machine
    shell: sleep 2 && shutdown -r now "Ansible updates triggered"
    async: 1
    poll: 0
    ignore_errors: true
    when: reboot_required_file.stat.exists
    - name: Waiting for the machine to come back
    local_action: wait_for host={{ ansible_host }} state=started port=22 delay=30
    become: no
    when: reboot_required_file.stat.exists

Y ejecútelo en la consola.

$ ansible-playbook act.yml -K

¡Listo!