ansible ignore the run_once configuration on task

…衆ロ難τιáo~ 提交于 2019-12-03 11:03:33

The run_once option will run every time your Playbook/tasks runs, but will only run it once during the specific run itself. So every time you run the play, it will run, but only on the first host in the list. If you're looking for a way to only run that command once, period, you'll need to use the creates argument. Using your example, this can be achieved by using the following -

- name: apt update
  shell: apt-get update && touch /root/.aptupdated
  args:
    creates: /root/.aptupdated

In this case the file /root/.aptupdated is created. The task will now check to see if that exists, and if it does it will not run.

On a related note if the task you are trying to run is the apt-get update, you may want to use the native apt module. You can then do something like this -

- name: apt update
  apt: update_cache=yes cache_valid_time=86400

Now this will only run if the cache is older than one day.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!