I should point out that trying to code in playbooks is usually the sign that you're trying too hard to do something.
It should almost always be thought of as "what is the easier way?" If syntax looks offensive, it is a sign simplification is needed -- that's the Ansible way, basically. A simple shell call to check if the particular directory is in the output of "mount" would be cleaner. - shell: blarg register: result - shell: baz when: foo in result.stdout OR - shell: baz when: foo.rc != 2 ETC would be preferable. Alternatively, you could also write a custom facts module that returned the mounts - action: my_mount_facts - shell: baz when: 'foo' in mounts etc Things like that. On Fri, Apr 4, 2014 at 9:02 AM, <[email protected]> wrote: > Hi Matt, > > That is a great suggestion! I will give it a try. > > I overcame this by using this task: > > - name: check mount point > shell: mount | sed -n -e '/\/var\/lib\/myMount.*/p' > register: result > > and after that using the result variable on the when statement: > > when: result.stdout=="" > > It looks like your solution is more straightforward. > > Thank you. > Regards, > Douglas > > > On Friday, April 4, 2014 9:16:19 AM UTC-3, Matt Martz wrote: > >> Douglas, >> >> You won't be able to use pure python in a when statement, you will have >> to handle it using jinja2. >> >> I see 2 options for you: >> >> 1) Use a combination of several jinja2 filters to get you what you want >> such as: >> >> when: >> ansible_mounts|map(attribute='mount')|intersect(['/var/lib/myMount'])|length >> == 0 >> >> 2) Create your own custom jinja2 filter to do this. >> >> -- >> Matt Martz >> [email protected] >> >> On April 3, 2014 at 10:27:23 PM, [email protected] ( >> [email protected]) wrote: >> >> Hi all, >> >> I was trying to update ansible from 1.2 to 1.5 and noticed that I can no >> longer use "only_if" which has been replaced by "when". >> >> But when I try to run a shell task with this condition: >> >> when: "len(filter(lambda m: m['mount'] == '/var/lib/myMount', >> '{{ansible_mounts}}')) == 0" >> >> I get the following error: >> >> error while evaluating conditional: len(filter(lambda m: m['mount'] == >> '/var/lib/myMount', '[{u'size_total': 8455118848, u'mount': u'/', >> u'size_available': 6891151360, u'fstype': u'ext4', u'device': >> u'/dev/xvda1', u'options': u'rw'}, {u'size_total': 16122802176, >> u'mount': u'/mnt', u'size_available': 15129432064, u'fstype': u'ext3', >> u'device': u'/dev/xvdb', u'options': u'rw,_netdev'}, {u'size_total': >> 107321753600, u'mount': u'/var/lib/myMount', u'size_available': >> 107250851840, u'fstype': u'xfs', u'device': u'/dev/xvdf', u'options': >> u'rw,noatime'}]')) == 0 >> >> The ansible_mounts variable is being correctly returned as you can see in >> the error message. >> >> I've tryed different combinations of positioning the quote marks but no >> luck. >> >> Any help? >> >> Regards, >> Douglas >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> >> To view this discussion on the web visit https://groups.google.com/d/ >> msgid/ansible-project/112db0a1-c88e-4bc5-a896- >> a9f738909391%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/112db0a1-c88e-4bc5-a896-a9f738909391%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> > On Friday, April 4, 2014 9:16:19 AM UTC-3, Matt Martz wrote: > >> Douglas, >> >> You won't be able to use pure python in a when statement, you will have >> to handle it using jinja2. >> >> I see 2 options for you: >> >> 1) Use a combination of several jinja2 filters to get you what you want >> such as: >> >> when: >> ansible_mounts|map(attribute='mount')|intersect(['/var/lib/myMount'])|length >> == 0 >> >> 2) Create your own custom jinja2 filter to do this. >> >> -- >> Matt Martz >> [email protected] >> >> On April 3, 2014 at 10:27:23 PM, [email protected] ( >> [email protected]) wrote: >> >> Hi all, >> >> I was trying to update ansible from 1.2 to 1.5 and noticed that I can no >> longer use "only_if" which has been replaced by "when". >> >> But when I try to run a shell task with this condition: >> >> when: "len(filter(lambda m: m['mount'] == '/var/lib/myMount', >> '{{ansible_mounts}}')) == 0" >> >> I get the following error: >> >> error while evaluating conditional: len(filter(lambda m: m['mount'] == >> '/var/lib/myMount', '[{u'size_total': 8455118848, u'mount': u'/', >> u'size_available': 6891151360, u'fstype': u'ext4', u'device': >> u'/dev/xvda1', u'options': u'rw'}, {u'size_total': 16122802176, >> u'mount': u'/mnt', u'size_available': 15129432064, u'fstype': u'ext3', >> u'device': u'/dev/xvdb', u'options': u'rw,_netdev'}, {u'size_total': >> 107321753600, u'mount': u'/var/lib/myMount', u'size_available': >> 107250851840, u'fstype': u'xfs', u'device': u'/dev/xvdf', u'options': >> u'rw,noatime'}]')) == 0 >> >> The ansible_mounts variable is being correctly returned as you can see in >> the error message. >> >> I've tryed different combinations of positioning the quote marks but no >> luck. >> >> Any help? >> >> Regards, >> Douglas >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> >> To view this discussion on the web visit https://groups.google.com/d/ >> msgid/ansible-project/112db0a1-c88e-4bc5-a896- >> a9f738909391%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/112db0a1-c88e-4bc5-a896-a9f738909391%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> > On Friday, April 4, 2014 9:16:19 AM UTC-3, Matt Martz wrote: > >> Douglas, >> >> You won't be able to use pure python in a when statement, you will have >> to handle it using jinja2. >> >> I see 2 options for you: >> >> 1) Use a combination of several jinja2 filters to get you what you want >> such as: >> >> when: >> ansible_mounts|map(attribute='mount')|intersect(['/var/lib/myMount'])|length >> == 0 >> >> 2) Create your own custom jinja2 filter to do this. >> >> -- >> Matt Martz >> [email protected] >> >> On April 3, 2014 at 10:27:23 PM, [email protected] ( >> [email protected]) wrote: >> >> Hi all, >> >> I was trying to update ansible from 1.2 to 1.5 and noticed that I can no >> longer use "only_if" which has been replaced by "when". >> >> But when I try to run a shell task with this condition: >> >> when: "len(filter(lambda m: m['mount'] == '/var/lib/myMount', >> '{{ansible_mounts}}')) == 0" >> >> I get the following error: >> >> error while evaluating conditional: len(filter(lambda m: m['mount'] == >> '/var/lib/myMount', '[{u'size_total': 8455118848, u'mount': u'/', >> u'size_available': 6891151360, u'fstype': u'ext4', u'device': >> u'/dev/xvda1', u'options': u'rw'}, {u'size_total': 16122802176, >> u'mount': u'/mnt', u'size_available': 15129432064, u'fstype': u'ext3', >> u'device': u'/dev/xvdb', u'options': u'rw,_netdev'}, {u'size_total': >> 107321753600, u'mount': u'/var/lib/myMount', u'size_available': >> 107250851840, u'fstype': u'xfs', u'device': u'/dev/xvdf', u'options': >> u'rw,noatime'}]')) == 0 >> >> The ansible_mounts variable is being correctly returned as you can see in >> the error message. >> >> I've tryed different combinations of positioning the quote marks but no >> luck. >> >> Any help? >> >> Regards, >> Douglas >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> >> To view this discussion on the web visit https://groups.google.com/d/ >> msgid/ansible-project/112db0a1-c88e-4bc5-a896- >> a9f738909391%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/112db0a1-c88e-4bc5-a896-a9f738909391%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/dac3566a-8812-4ede-b8cc-37f53ea7b439%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/dac3566a-8812-4ede-b8cc-37f53ea7b439%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEVJ8QPa0COo2rdrY0%3Duy64N%3DiUZ-Q060WUbHv3r5MiB4H%2Buvw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
