仅当日志文件不以开始时,才使用Ansible触摸日志文件__
使用仅当日志文件不以开始时,才使用Ansible触摸日志文件__,ansible,Ansible,使用Ansible 2.7.13,我试图在一个列表中执行一些日志文件,只有当文件名以\uuuuuu开头时。我似乎无法让它运行 这是我的密码: # file touch.yml - name: Touch file: path: "{{ item }}" state: touch mode: '0777' when: not (item | basename | regex_search("^__")) with_items: - "{{ touch_f
Ansible 2.7.13
,我试图在一个列表中执行一些日志文件,只有当文件名以\uuuuuu
开头时。我似乎无法让它运行
这是我的密码:
# file touch.yml
- name: Touch
file:
path: "{{ item }}"
state: touch
mode: '0777'
when: not (item | basename | regex_search("^__"))
with_items:
- "{{ touch_files }}"
我称之为
touch_files:
- "{{ path }}/job_count.json"
- "{{ path }}/query_time.json"
- "{{ path }}/disk_usage.json"
- "{{ path }}/__revert__"
其结果是:
错误when'不是一个有效的播放属性[0m
错误似乎出现在“…/playbooks/touch.yaml”中:第3行第3列,但可能在文件的其他位置,具体取决于语法问题。
预期结果:触摸touch_files
列表中列出的文件。不触摸_revert__文件
这里有什么问题
非常感谢
Q:“仅当文件名以_;开头时,才在列表中执行日志文件触摸”
答:代码中有问题
应在时
循环外使用
是一个列表;列表的循环列表无法工作touch_files
条件错误时当
- name: Touch
file:
path: "{{ item }}"
state: touch
mode: '0777'
loop: "{{ touch_files }}"
when: "item|basename is regex('^__(.*)$')"
(未测试)
Q:“仅当文件名以_;开头时,才在列表中执行日志文件触摸”
答:代码中有问题
应在时
循环外使用
是一个列表;列表的循环列表无法工作touch_files
条件错误时当
- name: Touch
file:
path: "{{ item }}"
state: touch
mode: '0777'
loop: "{{ touch_files }}"
when: "item|basename is regex('^__(.*)$')"
(未测试)此错误表明您尚未将任务包装到中。您需要指定任务将在其上运行的主机和其他可选设置
loop
现在比和_items
更可取。您还传递了一个列表列表
包含任务的示例剧本:
- hosts: <the-hosts-you-want-to-run-the-playbook-on>
tasks:
- name: Touch
file:
path: "{{ item }}"
state: touch
mode: '0777'
when: item | basename is startedwith '__'
loop: "{{ touch_files }}"
你可以把它放在很多地方,但最合适的地方可能是与你的剧本在同一个目录下的test\u plugins
目录中。调用文件startedwith.py
或你喜欢的任何东西
有关详细信息,请参阅。此错误表明您尚未将任务包装到中。您需要指定任务将在其上运行的主机和其他可选设置
loop
现在比和_items
更可取。您还传递了一个列表列表
包含任务的示例剧本:
- hosts: <the-hosts-you-want-to-run-the-playbook-on>
tasks:
- name: Touch
file:
path: "{{ item }}"
state: touch
mode: '0777'
when: item | basename is startedwith '__'
loop: "{{ touch_files }}"
你可以把它放在很多地方,但最合适的地方可能是与你的剧本在同一个目录下的test\u plugins
目录中。调用文件startedwith.py
或你喜欢的任何东西
有关详细信息,请参阅。您的剧本无效。您只列出了应作为剧本一部分的单个任务。请阅读剧本并将您的任务插入剧本中的有效剧本。剧本无效。您只列出了应作为剧本一部分的单个任务。请阅读剧本并将您的任务插入剧本中的有效剧本我的书。