I am using Ansible and I have a little problem trying to make idempotent a shell execution. The first I do is install python-apt package because I need it to use the apt module for install others packages. But every time that I run my playbook the shell task always runs and I want to make it idempotent. Here is my shell task:
- name: install pyton-apt
shell: apt-get install -y python-apt
And here is the output, always running the above task:
$ ansible-playbook -i hosts site.yml
PLAY [docker] *****************************************************************
GATHERING FACTS ***************************************************************
ok: [10.0.3.240]
TASK: [docker | install pyton-apt] ********************************************
changed: [10.0.3.240]
TASK: [docker | install unzip] ************************************************
ok: [10.0.3.240]
PLAY RECAP ********************************************************************
10.0.3.240 : ok=3 changed=1 unreachable=0 failed=0
You should use the ansible
apt
module to installpython-apt
, which will be idempotent out of the box: http://docs.ansible.com/apt_module.htmlE.g.
(Note using the apt module should automatically install
python-apt
on the remote host so I'm not sure why you would need to manually install it, see https://github.com/ansible/ansible/issues/4079)Edit: If for some reason you can't use the inbuilt
apt
module to install python apt, theshell
module provides thecreates
parameter to help make it idempotent.What this means is that the shell module will not run if
/home/x/output.log
already exists.