Ansible 命令忽略创建

tri*_*lef 3 command ansible ansible-playbook

我使用command具有createsansible 2.9 角色的模块。

但是,有时我需要忽略createsarg 并多次重新运行该命令。

有什么办法可以覆盖默认行为并强制执行任务吗?

Zei*_*tor 6

一种非常基本的解决方案。在您的任务中:

- name: Do command optionally ignoring create option
  command:
    cmd: touch /tmp/toto.txt
    creates: "{{ ignore_creates | default(false) | bool | ternary('', '/tmp/toto.txt') | default(omit, true) }}"
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用额外的 var 启动您的剧本,-e ignore_creates=true以强制任务运行,即使文件存在。删除命令中额外的 var 将再次打开条件。