# Ansible First Steps with apt-get playbook

**URL:** <https://forum.ansible.com/t/ansible-first-steps-with-apt-get-playbook/17410>\
**Category:** Ansible Project\
**Created:** [February 1, 2015, 7:01pm UTC](https://forum.ansible.com/t/ansible-first-steps-with-apt-get-playbook/17410 "2015-02-01T19:01:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anatol](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Anatol](https://forum.ansible.com/u/Anatol)\
**Post date:** [February 1, 2015, 7:01pm UTC](https://forum.ansible.com/t/ansible-first-steps-with-apt-get-playbook/17410/1 "2015-02-01T19:01:04Z")

</div>

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:

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 2, 2015, 3:00pm UTC](https://forum.ansible.com/t/ansible-first-steps-with-apt-get-playbook/17410/2 "2015-02-02T15:00:59Z")

</div>

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  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmpfile: /tmp/security.sources.list  
&nbsp;&nbsp;tasks:

&nbsp;&nbsp;&nbsp;&nbsp;- name: update apt Cache  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt: update\_cache=true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sudo: yes

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

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

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

---

<div class="post-metadata">

**Author:** ![Anatol](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Anatol](https://forum.ansible.com/u/Anatol)\
**Post date:** [February 2, 2015, 5:25pm UTC](https://forum.ansible.com/t/ansible-first-steps-with-apt-get-playbook/17410/3 "2015-02-02T17:25:41Z")

</div>

Thanks – this makes sense.

cheers,

Anatol

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 2, 2015, 5:39pm UTC](https://forum.ansible.com/t/ansible-first-steps-with-apt-get-playbook/17410/4 "2015-02-02T17:39:58Z")

</div>

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

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