如何删除 ansible 中 copy/template 模块的 'all other' 文件?
How to remove 'all other' files for copy/template modules in ansible?
小任务:
- name: Configure hosts
template: src=host.cfg.j2 dest=/etc/shinken/hosts/{{item.host_name}}.cfg
with_items: shinken_hosts
when: shinken_hosts is defined
notify: reload config
我想删除 /etc/shinken/hosts/ 中由此任务配置的所有其他配置(文件)。
我该怎么做?
(如果我在 'shinken_hosts' 中修正了一个拼写错误并且想要自动删除名称错误的旧配置,这真的很重要)。
您可能需要检查 this,幻灯片 19。
这假定您知道特定目录中需要存在哪些文件,然后删除所有其他文件。
# tidy_expected: [‘conf1.cfg’, conf2.cfg’]
- find: paths={{tidy_path}} #/etc/myapp
register: existing
- file: path={{item.path}} state=absent
when: item.path|basename not in tidy_expected
with_items: “{{existing.files|default([ ])}}”
register: removed
- mail: body=“{{removed}}”
小任务:
- name: Configure hosts
template: src=host.cfg.j2 dest=/etc/shinken/hosts/{{item.host_name}}.cfg
with_items: shinken_hosts
when: shinken_hosts is defined
notify: reload config
我想删除 /etc/shinken/hosts/ 中由此任务配置的所有其他配置(文件)。
我该怎么做?
(如果我在 'shinken_hosts' 中修正了一个拼写错误并且想要自动删除名称错误的旧配置,这真的很重要)。
您可能需要检查 this,幻灯片 19。 这假定您知道特定目录中需要存在哪些文件,然后删除所有其他文件。
# tidy_expected: [‘conf1.cfg’, conf2.cfg’]
- find: paths={{tidy_path}} #/etc/myapp
register: existing
- file: path={{item.path}} state=absent
when: item.path|basename not in tidy_expected
with_items: “{{existing.files|default([ ])}}”
register: removed
- mail: body=“{{removed}}”