Loop from 0 to 100 with ansible

Viewed 205

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?

1 Answers

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']
Related