Ansible:查找/path/*/filename并更改几行

Ansible:查找/path/*/filename并更改几行,ansible,Ansible,这是我的目录树: . ├── unknown_dir1 │   └── firefox.conf └── unknown_dir2 └── firefox.conf 我需要找到文件firefox.conf的每个实例,并更改它们的一些参数。 我的任务如下: - name: configure firefox lineinfile: dest= [?] state=present regexp=.*{{ item.value }}.* line

这是我的目录树:

.
├── unknown_dir1
│   └── firefox.conf
└── unknown_dir2
    └── firefox.conf
我需要找到文件
firefox.conf
的每个实例,并更改它们的一些参数。 我的任务如下:

- name: configure firefox
   lineinfile:
     dest= [?]
     state=present
     regexp=.*{{ item.value }}.*
     line='user_pref("{{ item.value }}", {{ item.key }});'
     insertafter=EOF
     backup=yes
   with_tems:
     - { value: 'browser.startup.page', key: '0' }
     - { value: 'network.cookie.cookieBehavior', key: '3' }
问题是firefox.conf文件位于未知目录下

如何搜索每个文件实例并在
lineinfile
模块的
dest
条目中指定它

我试图在预结束的任务之前注册
find
命令的输出:

- name: find firefox.confs
  shell: find /vagrant/* -type f -name "firefox.conf"
  register: files_to_change

但是,在
配置firefox
任务的
部分,我找不到如何处理
中的列表和字典,其中包含
/
嵌套的
/
子元素
/
您可以命名它。
我相信这就是您想要的:

- name: configure firefox
   lineinfile:
     dest={{ item[0] }}
     state=present
     regexp=.*{{ item[1].value }}.*
     line='user_pref("{{ item[1].value }}", {{ item[1].key }});'
     insertafter=EOF
     backup=yes
   with_nested:
    - files_to_change.stdout_lines
    -
     - { value: 'browser.startup.page', key: '0' }
     - { value: 'network.cookie.cookieBehavior', key: '3' }
说明:


将对上一个任务的输出找到的每个文件应用lineinfile替换

的确如此。关键是所有firefox值都作为第二个条目的子条目输入。非常感谢。