Answers: <p>Copy module should work</p>
  
  <pre><code>- hosts: all  
    tasks:
      - copy:
          src: /data/new_config
          dest: /opt/zservice/etc/config
          owner: root
          group: wheel
          mode: '0750'
          backup: yes
  </code></pre>
  
  <p>If you worry about the number of the hosts take a look at <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html#rolling-update-batch-size" rel="nofollow noreferrer">serial</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-07-21T13:18:38.280Z
Answers: 2019-07-21T13:18:38.280Z
Answers: Vladimir Botka
Answers: <p>You can use Ansible’s template module transfers templated files to remote hosts. 
  It works similarly to the copy module, but with  major difference:</p>
  
  <p>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. </p>
  
  <pre><code>- 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
  </code></pre>
  
  <p>For more details see <a href="https://docs.ansible.com/ansible/latest/modules/template_module.html" rel="nofollow noreferrer">ansible template module</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2019-07-24T17:10:58.917Z
Answers: 2019-07-24T17:10:58.917Z
Answers: Fodil
Body: <p>I have a bash script on about 70 severs in <code>/opt/zservice/etc/config</code> that i want to change its content with ansible. the new content is on ansible server in this path <code>/data/new_config</code>.<br>
  how i can use ansible (how to write a task) that reads this file <code>new_config</code> and then replace <code>config</code> content ?  </p>
  
  <p>something like this in bash: <code>/data/new_config &gt; /opt/zservice/etc/config</code></p>
  
Tags: <ansible><linux><centos>
Title: copy contents of file on ansible server to another file on remote servers
UserDisplayName: BlackCrystal
ThreadText: # copy contents of file on ansible server to another file on remote servers
  
  (Asked by: username_0 on 2019-07-21)
  
  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`
  
  **Tags:** ansible, linux, centos
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-07-21. Score: 1 | Accepted answer
  
  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](https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html#rolling-update-batch-size).
  
  
  ---
  
  ### Answer by username_2 on 2019-07-24. Score: 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](https://docs.ansible.com/ansible/latest/modules/template_module.html)
  
  
  ---
  
  