A general question about looping

14 vues
Accéder directement au premier message non lu

Mike Eggleston

non lue,
10 déc. 2021, 16:05:3110/12/2021
à ansible...@googlegroups.com
I know I can do this from a shell script. I wonder if I can do this in pure Ansible.
I was thinking about clusters recently. I know I can use the VM module to spin up a VM.
If I wanted 1,000 nodes, how would I loop inside Ansible for the nodes?
Using the shell I would do something like (not tested):

for i in `seq 000 999`
do
ansible-playbook -e nodename=“beofulfnode$i” create-a-node.yml
done

How to do this looping in pure Ansible?

Mike

Jorge Rúa

non lue,
10 déc. 2021, 16:29:2410/12/2021
à ansible...@googlegroups.com
Have a look to with_sequence 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/A6093B7A-C19D-4060-9320-A2F50540677B%40gmail.com.

Todd Lewis

non lue,
10 déc. 2021, 16:55:1710/12/2021
à Ansible Project
It's something close to this, but "create-a-node.yml" isn't a playbook in this case, but rather just a task file.

- name: loop over beofulf nodes
  include_tasks: create-a-node.yml
  with_sequence: start=000 end=999
  vars:
    nodename: "beofulfnode{{ item }}"

Dick Visser

non lue,
11 déc. 2021, 03:23:0811/12/2021
à ansible...@googlegroups.com
Apparently the recommendation these days is to use the range filter:


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Todd Lewis

non lue,
13 déc. 2021, 08:11:2213/12/2021
à Ansible Project
  - name: loop over beofulf nodes
    include_tasks: create-a-node.yml
    loop: "{{ range(0, 1000) | list }}"
    vars:
      nodename: "{{ 'beofulfnode%03d' | format(item) }}"

Mike Eggleston

non lue,
13 déc. 2021, 09:11:5513/12/2021
à ansible...@googlegroups.com
Thank you to everyone. :)

Mike

Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message