Ansible First Steps with apt-get playbook

Hi there,

I´m starting learning ansible and I can say I´m getting addicted! Great Software!

May one look at my first try for a playbook and tell me if this is the way to go:

Given is following bash code to run only security upgrades on a linux box

TMP=/tmp/security.sources.list grep security /etc/apt/sources.list > $TMP apt-get upgrade -oDir::Etc::Sourcelist=$TMP "$@" rm $TMP

Which I would transfer into a playbook like this:

`

Each ansible task runs under it's own connection, so setting TMP in
one will not be inherited by the others.

try this:

- hosts: webservers
  vars:
     tmpfile: /tmp/security.sources.list
  tasks:

    - name: update apt Cache
      apt: update_cache=true
      sudo: yes

    - name: grep security sources
      command: grep security /etc/apt/sources.list > {{tmpfile}}

    - name: run upgrade
      command: apt-get upgrade -oDir::Etc::Sourcelist={{tmpfile}} "$@"
      sudo: yes

    - name: Remove TMP File
      file: path={{tmpfile}} state=absent

Thanks – this makes sense.

cheers,

Anatol

also, when using pipes or redirection use shell module instead of command:

shell: grep security /etc/apt/sources.list > {{tmpfile}}