guys, I want to use ansible to open a file, for example pg_hba.conf in realtime (like vim) and be able to edit it on the fly. I want to be able to choose the group of target servers from jenkins, read the contents of pg_hba.conf of a particular node, and pass these contents as parameter, which I can edit in a free form text. After I press a "build" button to save the new changes into the group of nodes.
Asked
Active
Viewed 224 times
2 Answers
0
You can use this with ansible modules like copy, template, lineinfile, blockinfile.
I think the best way is using template module but some time lineinfile will be work for you (See official ansible module documentation).
As current working example for your problem, see this git repo.
Let me know if you have any problem.

Ocean
- 2,882
- 1
- 18
- 21
-
I want before the edit to display the contents of the particular pg_hba.conf file – Grigor Ivanov Jan 28 '19 at 13:50
-
I didn't get your problem. Could you please describe why do you want to display content of pg_hba.conf!? – Ocean Jan 28 '19 at 16:00
-
You can use the `slurp` module to retrieve the base64 contents of a file (https://docs.ansible.com/ansible/latest/modules/slurp_module.html): "This module works like fetch. It is used for fetching a base64- encoded blob containing the data in a remote file". You can register the results and print the contents on screen with the `debug` module (e.g. check the modules examples). – masseyb Jan 28 '19 at 16:50
-
Masseyb, thanks for the replay. I've did something similar, instead of slurp, I've used "cat" command in a shell command. With slurp the data is displayed on one row. – Grigor Ivanov Jan 30 '19 at 06:54
0
Here's my solution:
tasks:
-
name: cat the pg_file
shell: cat "{{ pg_path }}"
register: predata
- debug:
msg: "{{predata.stdout_lines|list}}"

Grigor Ivanov
- 9
- 1