Ask about "side by side" loop

7 views
Skip to first unread message

aldyth maharsha

unread,
Jul 20, 2017, 11:04:54 AM7/20/17
to Ansible Project
Hi All

I have question and I'm newbie in ansible...I try to clone multiple vm from template in vmware with each of them have different ip address..Example my script below

---
- hosts: localhost
  connection: local
  vars:
     vcenter: vcenter01
     datastore: datastore-1
     datacenter: dc01
     vmcluster: cluster01
     vmtemplate: OEL69

  tasks:
   - name: Create vm from template
     vmware_guest:
         hostname: "{{ vcenter }}"
         username: admini...@vsphere.local
         password: secret
         validate_certs: no
         datacenter: "{{ datacenter }}"
         name: "webapps-{{ item }}"
         template: "{{ vmtemplate }}"
         cluster: "{{ vmcluster }}"
         folder: "/APPS"
         state: poweredon
     with_sequence: start=1 end=20

I can clone 20 vm from template successfully but when I tried to assign IP address I dont know how to create side by side loop like this

webapps-1 192.168.10.101
webapps-2 192.168.10.102
webapps-3 192.168.10.103

and so on until 20...So how to create side by side loop with different iteration?...Thank you

Branko Majic

unread,
Jul 20, 2017, 3:46:11 PM7/20/17
to ansible...@googlegroups.com
On Thu, 20 Jul 2017 08:04:54 -0700 (PDT)
aldyth maharsha <aldy...@gmail.com> wrote:

> Hi All
>
> I have question and I'm newbie in ansible...I try to clone multiple
> vm from template in vmware with each of them have different ip
> address.
>
> I can clone 20 vm from template successfully but when I tried to
> assign IP address I dont know how to create side by side loop like
> this
>
> webapps-1 192.168.10.101
> webapps-2 192.168.10.102
> webapps-3 192.168.10.103
>
> and so on until 20...So how to create side by side loop with
> different iteration?...Thank you

Did you consider using a bit of arithmetic instead? Or this is not
flexible enough for you?

E.g. you could do "{{ 100 + item | int }}" (take note you need the "|
int" on item because it's a string). Preferably you'd make the "100" a
parameter instead of leaving it in as magic, of course :)

Best regards

--
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.
Reply all
Reply to author
Forward
0 new messages