Conditionally execute command

21 views
Skip to first unread message

tipytop

unread,
Aug 15, 2014, 9:57:26 AM8/15/14
to ansible...@googlegroups.com
Hi,

i have a following problem. I am building OpenStack which uses tool openstack-config for setting value in configuration files.

To get value:
openstack-config --get /etc/keystone/keystone.conf sql connection
To set value:
openstack-config --set /etc/keystone/keystone.conf sql connection {{ VALUE }}

So now I want to check if previous value matches the value I provide. If they do match, than it should report OK, otherwise CHANGED. Current solution is to register shell result of GET command and conditionally execute SET command, but I don't like that very much because I have to do that 50-100 times; therefore code would be quite unreadable.

Does ansible provide easy mechanism to merge these two tasks or is copying ansible shell module and extending it the only solution?

PS: sorry for bad title 

Michael DeHaan

unread,
Aug 15, 2014, 3:46:02 PM8/15/14
to ansible...@googlegroups.com
I would use the shell module to register to check the first value.

Then key off the saved_value.stdout or saved_value.rc on the conditional of the second.

It may make sense to have an openstack_config module, but I suspect many folks *might* just template the config files directly.  Depends where they are stored.






--
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/277b82a0-8325-4207-b732-637a6b61e8b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages