google-cloud-ops-agents-ansible icon indicating copy to clipboard operation
google-cloud-ops-agents-ansible copied to clipboard

Use template module

Open tejas-2232 opened this issue 2 years ago • 0 comments

Use template ansible module to place file to desired destination.

For ex: In google-cloud-ops-agents-ansible/tasks/linux.yml

on line 35 we have

- when: package_state == 'present'
  block:
    - name: Copy main config file onto the remote machine
      copy:
        src: "{{ main_config_file }}"
        dest: "{{ vars[agent_type + '_config_path'] }}"
        force: true
        mode: 0644

Copy module will only copy the same file present on host machine.

The template module takes the file from host, changes the variables if required by end-user, and then copies to the remote location, provided the file should be present in templates directory besides the tasks directory

Solution:

- when: package_state == 'present'
  block:
    - name: Copy main config file onto the remote machine
      template:
        src: "{{ main_config_file }}"
        dest: "{{ vars[agent_type + '_config_path'] }}"
        force: true
        mode: 0644

tejas-2232 avatar Jan 11 '23 11:01 tejas-2232