# Run 'aptitude safe-upgrade' on all registered hosts.
#
# The output of each update is appended to `myfineupdate.log`, a locally
# created file.
#
# Run like:
#
#   $ ansible-playbook -i hosts playbook-daily-upgrade.yml
#
- hosts: all
  become: true
  become_user: root
  tasks:
  - name: safe-upgrade
    register: upgrade
    apt:
        update_cache: yes
        upgrade: safe
  - name: "log-to myfineupdate.log"
    local_action: shell echo "{{ inventory_hostname }}:\n  {{ '\n  '.join(upgrade.stdout_lines) }}  {{ '\n  '.join(upgrade.stderr_lines) }}" >> "myfineupdate.log"
    become: false
    changed_when: false
