run tasks based on variable

100 views
Skip to first unread message

Bill Nolf

unread,
Dec 4, 2018, 2:03:21 PM12/4/18
to Ansible Project
I have the following vars:

vms
      test1
        name: test1
        disk_size:
           - size: 10
           - size: 20

     test2
        name: test2
        disk_size:
            - size: 10

I need to be able to set tasks on test1 and
then the same set on test2.  Is there a way to do
this in ansible?

thanks
   
     

Bill Nolf

unread,
Dec 4, 2018, 2:03:52 PM12/4/18
to Ansible Project
Ansible 2.4

Piotr Owcarz

unread,
Dec 4, 2018, 2:31:27 PM12/4/18
to ansible...@googlegroups.com
Yes


--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/89d7f81d-33e5-4ffa-876d-b261bc4fa792%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bill Nolf

unread,
Dec 4, 2018, 2:32:50 PM12/4/18
to ansible...@googlegroups.com
How

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/gbISAz0cqzw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Piotr Owcarz

unread,
Dec 4, 2018, 2:33:58 PM12/4/18
to ansible...@googlegroups.com
Depends on what you actually want to do.


Bill Nolf

unread,
Dec 5, 2018, 7:32:57 AM12/5/18
to Ansible Project
What I'm try to do is create argument string that needs to be run each time the name of the vm changes.
The argument contains the name and uses the disk size.

I was able to build an array containing the correct argument string but it uses all disks.

example
    --disk name=test1 size 10
    --disk name=test1 size 20
    --disk name=test2 size 20

What I need is
   
    --disk name=test1 size 10
    --disk name=test1 size 10
run command
   
     --disk name=test2 size 20
run command

The number of vms could be 1 to many

thanks



On Tuesday, December 4, 2018 at 2:03:21 PM UTC-5, Bill Nolf wrote:

Piotr Owcarz

unread,
Dec 5, 2018, 12:12:53 PM12/5/18
to ansible...@googlegroups.com
Hi Bill


Piotr 


--
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 post to this group, send email to ansible...@googlegroups.com.

Bill Nolf

unread,
Dec 10, 2018, 7:26:46 AM12/10/18
to ansible...@googlegroups.com
I don’t think that is what I need 
I need to do something like
If name not equal previous-name; then
    viirt-install disk-arg
    previous-name =name
    disk-arg = “”
else
     disks-arg=disk-arg+ disk
fi

Thanks 

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/gbISAz0cqzw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Piotr Owcarz

unread,
Dec 10, 2018, 8:28:40 AM12/10/18
to ansible...@googlegroups.com
Bill,
You are giving very little information... please spend some time and describe in details what your idea is, plus some extra answers:
How does Ansible know what the previous-name was? How do you store the previous-name value for the next playbook run?
Are you running playbook periodically? Are you executing the playbook per VM, or do you store all VMs configurations in yaml?
At what stage of developing the playbook are you? Send us what you already got, with the -vvv output and explanaition what did you expect vs what the playbook actually did.

Regards,
Piotr




Bill Nolf

unread,
Dec 10, 2018, 8:39:48 AM12/10/18
to ansible...@googlegroups.com
Sorry I will try to give more details 

Bill Nolf

unread,
Dec 10, 2018, 9:43:16 AM12/10/18
to ansible...@googlegroups.com
The playbook is run each time a vm needs to be allocated. The details for each vm is store in the group_vars file as follows:
vms
       one
           - name:  vmone
           - mem: 4096
           - cpus: 2
           - disks
                  - size: 10
                  - size: 20
       two
             - name: vmtwo
             - mem: 4096
             - cpus: 1
             - disks:
                     - size: 10

How to set the previous name and how to loop through each VM is the problem I’m having.  I can store the disk into an array. Vm s have one or two disks. I want to process the disk for vmone and run virt-install then repeat for vmtwo, etc
I wish I could give you the playbooks but they reside on another network which I can’t download from. 
I hope this provides enough info that you are able to give me something to work with. Once I have a starting point I will work with it until I’m able to get it to do what I need
Thanks 

On Mon, Dec 10, 2018 at 8:28 AM Piotr Owcarz <pow...@gmail.com> wrote:

Piotr Owcarz

unread,
Dec 10, 2018, 6:52:15 PM12/10/18
to ansible...@googlegroups.com
Sorry Bill, I can't help you if you don't cooperate. I am not going to waste my time on guessing what you are trying to do. Maybe someone else is willing asking you over and over. 
I can only suggest you to check virt and virt_pool because since you are mentioning  virt-install command.

Good luck
Piotr

Bill Nolf

unread,
Dec 10, 2018, 9:37:37 PM12/10/18
to ansible...@googlegroups.com
Thanks. I was trying to explain what I was trying to do. Sorry for wasting your time

Karl Auer

unread,
Dec 10, 2018, 10:21:22 PM12/10/18
to ansible-project
Hey Bill.

We would like to help. But we simply do not know what you are trying to achieve. Just tell us, in plain terms, what you are trying to do. Not the details, not the Ansible code - just the end result you seek. We can drill down from that.

Also, those playbooks that you cannot download: What do they do (in very plain terms - inputs and outputs)?

You may be better off setting up a testbed where you control all the components; then you can make playbooks you DO control to emulate the ones on the remotes that you can't see.
You might also like to break your overall job down into smaller testable chunks, such as detecting a change of name, executing a command, iterating over a group, building a suitable command and so on.
I'm afraid I know zilch about (VMWare?) VMs, so can't help with the detail.

Regards, K.


For more options, visit https://groups.google.com/d/optout.


--
Karl Auer

Email  : ka...@2pisoftware.com
Website: http://2pisoftware.com


GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

Reply all
Reply to author
Forward
0 new messages