简体   繁体   中英

Online edit a file(pg_hba.conf) using ansible and jenkins

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.

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.

Here's my solution:

tasks:
    -
      name: cat the pg_file
      shell: cat "{{ pg_path }}"
      register: predata
    - debug:
        msg: "{{predata.stdout_lines|list}}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM