N
N
Nikolai Savelyev2017-05-17 09:01:28
linux
Nikolai Savelyev, 2017-05-17 09:01:28

Is it possible to find a file with ansible and insert a string into it?

In the documentation for ansible, pre-known paths to files are indicated everywhere. But what if this path still needs to be found?
I want to edit custom prefs.js with ansible. Everything is clear - lineinfile easily and simply inserts lines in the right place. But there are almost 100 users, and the files are in the /home/username/.mozilla/firefox/account.default/prefs.js folders. That is, you must first find the path to the file, and then substitute the lines.
Can someone tell me how to find a file in one playbook and then pass its path to lineinfile?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konkase, 2017-05-17
@nikweter

docs.ansible.com/ansible/playbooks_conditionals.ht...
docs.ansible.com/ansible/playbooks_loops.html

- command: find /home/ -name 'prefs.js' 2>/dev/null
  register: prefs

- lineinfile: 
    dest: "{{ item }}"
    ...
  with_items: "{{ prefs.stdout_lines }}"

P
Puma Thailand, 2017-05-17
@opium

It’s not very clear why you need to look for paths that seem to be known,
just make a task from the list of users
and get it with the same ls

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question