Search code examples
variablesansiblewin-shell

Ansible put in same option command all values of elements of list


OS: W2K16 Server Ansible: 2.9.9

I search the method to put several vars in the winshell command, but this code launch 3 time the winshell command:

- name: "ntp conf"
  win_shell: | 
  'w32tm /config /manualpeerlist: {{ item }} /syncfromflags:MANUAL'
  with_items:
   - 192.168.0.1
   - 192.168.0.10
   - 192.168.0.100

I Desire, the command is launched:

w32tm /config /manualpeerlist:"192.168.0.1 192.168.0.10 192.168.0.100" /syncfromflags:MANUAL'

Please don't referme to "ntp" ansible module, this is a example, I need to understand how to get multiple values from a list and run with one shoot.

Thank's a lot!


Solution

  • Put the peers into a list and join the items, e.g.

        - command:
            cmd: |
              echo "{{ _peers|join(' ') }}"
          register: result
          vars:
            _peers:
              - 192.168.0.1
              - 192.168.0.10
              - 192.168.0.100
        - debug:
            var: result.stdout
    

    gives

      result.stdout: 192.168.0.1 192.168.0.10 192.168.0.100