1

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!

CH06
  • 139
  • 2
  • 14
  • `with_items` is a `"for loop"` that is running based on the `list` of IP addresses you provided. So it is doing its work as expected. What was the reason you went for `with_items`? you can simply assign all these 3 ips to a variable with space seperated and pass that variable to your command in `winshell` here is the documentation for loops https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html – JBone Jun 29 '21 at 14:24

1 Answers1

1

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
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63