Answer the question
In order to leave comments, you need to log in
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
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 }}"
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 questionAsk a Question
731 491 924 answers to any question