ansible conditions

48 views
Skip to first unread message

Sudhir Kumar

unread,
Feb 1, 2018, 10:41:08 AM2/1/18
to Ansible Project
Hi,

Below snippet sometimes working and sometimes failing. So, i am executing it with jenkins and idea is that if parameter is defined then script should run otherwise it should not run. 

Can anyone please enlighten me what's wrong ?

#############
  - name: Executing lvm script 
    shell: /tmp/lvm-script.sh sdb {{ vg_name }} {{ mtpt_size }} 
    args:
      chdir: /tmp/
    when: vg_name is defined
##########

Sudhir Kumar

unread,
Feb 2, 2018, 6:56:23 AM2/2/18
to Ansible Project
Hi All,

Any ideas ?

Sidh

Kai Stian Olstad

unread,
Feb 2, 2018, 8:35:22 AM2/2/18
to ansible...@googlegroups.com
On Friday, 2 February 2018 12.56.23 CET Sudhir Kumar wrote:
> Hi All,
>
> Any ideas ?

Not without the actual error message you get.

--
Kai Stian Olstad

Sudhir Kumar

unread,
Feb 2, 2018, 8:18:52 PM2/2/18
to Ansible Project

when: is not working as expected, So, even if i don't pass parameters then also it tries to run and then fails. So error is : from script i.e. parameters not passed. 
But ideally, it should skip this if parameter is not supplied.

Regards,
Sidh

rhys.jame...@googlemail.com

unread,
Feb 3, 2018, 1:31:50 PM2/3/18
to Ansible Project
Is it possible the varibale is defined but unset. Why not test that the length of string is > 0 instead?

Sudhir Kumar

unread,
Feb 3, 2018, 6:11:17 PM2/3/18
to Ansible Project
Can you please give me an example for that or refer documentation on how can i do this : "when' in ansible ?

Varun Chopra

unread,
Feb 4, 2018, 6:20:36 AM2/4/18
to Ansible Project
Hi Sudhir,

You're barely making sense and it doesn't help when you don't provide any code.

Nobody can help you if they don't understand you.

--
Varun

Sudhir Kumar

unread,
Feb 4, 2018, 3:04:02 PM2/4/18
to Ansible Project
Hi All,

Seems like some miscommunication here. I provided code in my first comment :

#############
  - name: Executing lvm script 
    shell: /tmp/lvm-script.sh sdb {{ vg_name }} {{ mtpt_size }} 
    args:
      chdir: /tmp/
    when: vg_name is defined
##########

And using with  jenkins + parameterized input. 

So, if any parameterized input present then ansible should fire above script . If no input is provided then it should not trigger above snippet. 

Hope it's clear now.

Regards,
Sidh

eshan TANDON

unread,
Feb 4, 2018, 3:22:33 PM2/4/18
to ansible...@googlegroups.com
Hi Sudhir,
Try logging the actual values:
- debug: var=vg_name verbosity=3
- debug: var=mtpt_size verbosity=3

Thanks,
Eshan


--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/706a2822-ca39-4a02-a397-941819bc819f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Warm Regards,
Eshan Tandon

Sidh

unread,
Feb 5, 2018, 7:14:24 AM2/5/18
to Ansible Project
Thanks, got more info after debugging. 
It's resolved. Idea and when condition was ok. Only issue was that i was evaluating wrong parameterized input in this case.

Regards,
Sidh
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.
Reply all
Reply to author
Forward
0 new messages