2

I would like to loop from s0 to s60 and from s100 to s100 with this command:

- name: "Network scan at port 22 {{ nom_base }}"
  when: inventory_hostname in groups['exos_switch']
  wait_for:
        port: 22
        host: "{{ nom_base }}-{{ item }}"
        state: started
        timeout: 2   
  with_items:
    - s0
    - s1
    - s2
    - s3
    - s4
    - s5
    ....
    - s60
    - s100
    ...
    - s110

Any idea?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Benoit
  • 23
  • 3
  • 4
    https://docs.ansible.com/ansible/2.7/user_guide/playbooks_loops.html#with-sequence – Mickael B. Oct 07 '21 at 13:50
  • 1
    Does this answer your question? [Ansible with items in range](https://stackoverflow.com/questions/48653092/ansible-with-items-in-range) – U880D Oct 07 '21 at 14:48
  • I can do that with "with_sequence" but i must jump some number – Benoit Oct 07 '21 at 14:51
  • 1
    => Try this oneliner to get a list of your needed values`ansible localhost -m debug -a "msg={{ (range(0,61) | list) + (range(100,111) | list) }}"`. Use accordingly in your playbook. – Zeitounator Oct 07 '21 at 15:49

1 Answers1

0

In respect to your question and comment a solution like

- name: Show sequence
  debug:
    msg: "s{{ item }}"
  with_sequence:
    - "0-60"
    - "100-110"
  tags: seq

might work for you.

- name: "Network scan at port 22 {{ nom_base }}"
  wait_for:
        port: 22
        host: "{{ nom_base }}-s{{ item }}"
        state: started
        timeout: 2   
  with_sequence:
    - "0-60"
    - "100-110"
  when: inventory_hostname in groups['exos_switch']
U880D
  • 8,601
  • 6
  • 24
  • 40