0

I have a bash script on about 70 severs in /opt/zservice/etc/config that i want to change its content with ansible. the new content is on ansible server in this path /data/new_config.
how i can use ansible (how to write a task) that reads this file new_config and then replace config content ?

something like this in bash: /data/new_config > /opt/zservice/etc/config

2 Answers 2

1

Copy module should work

- hosts: all  
  tasks:
    - copy:
        src: /data/new_config
        dest: /opt/zservice/etc/config
        owner: root
        group: wheel
        mode: '0750'
        backup: yes

If you worry about the number of the hosts take a look at serial.

1

You can use Ansible’s template module transfers templated files to remote hosts. It works similarly to the copy module, but with major difference:

You can use the jinja2 templating language in your files, which will be templated out separately for each remote host and you can have conditional statements, loops, filters for transforming the data, do arithmetic calculations, etc.

- hosts: all  
  tasks:

    - name: Update config on remote servers 
      template:
        #src: Update_config.j2  using jinja2 templating language, if we need  
                               transforming data 
        src: /data/new_config  # Static 
        dest: /opt/zservice/etc/config
        force: yes
        backup: yes

For more details see ansible template module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.