我正在使用Ansible,我在尝试将幂等函数作为shell执行时遇到了一个小问题。我做的第一件事是安装python包,因为我需要它来使用apt模块安装其他软件包。但是每次我运行我的剧本时,shell任务总是运行,我想使它成为幂等的。下面是我的shell任务:
- name: install pyton-apt
shell: apt-get install -y python-apt这是输出,总是运行上面的任务:
$ 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 发布于 2014-07-04 15:29:03
您应该使用ansible apt模块来安装python-apt,这将是开箱即用的:module.html
例如。
- name: install python-apt
apt: name=python-apt state=present(注意使用apt模块应该在远程主机上自动安装python-apt,所以我不知道为什么需要手动安装它,参见https://github.com/ansible/ansible/issues/4079)
编辑:如果由于某种原因无法使用内置的apt模块安装python,则shell模块提供creates参数以帮助使其成为幂等函数。
- name: install python-apt
shell: apt-get install -y python-apt >> /home/x/output.log creates=/home/x/output.log这意味着如果/home/x/output.log已经存在,shell模块将不会运行。
https://stackoverflow.com/questions/24576315
复制相似问题