4 ms·
While pure python executions would be nice (and are possible[1]), your examples are easily represented in the yaml files as well: --- - servers: webser
by falcolas 13y ago
While pure python executions would be nice (and are possible[1]), your examples are easily represented in the yaml files as well:
---
- servers: webservers
- tasks
- file: mode=0755 path=/var/lib/somefile
...
---
- servers: qa_servers
- tasks
- lineinfile: dest=/etc/profile line='EXPORT RUBY_ENV=QA' state=present
[1] http://www.ansibleworks.com/docs/api.html http://www.ansibleworks.com/docs/api.html
[EDIT]: Dropped names from tasks to make examples clearer.
- dalore 13y agoTo nitpick, his example is slightly different. His goes through server by server and then does the 2 lines (if they match the name). Yours does the first task on all the webservers first and then the next part on all the qa_servers. In theory should produce the same output, but if something relied on doing it the first way that would be the difference.
- falcolas 13y agoTrue, though as you note it's a subtle difference, and in my experience not something I've had to differentiate on. If you really needed the second task to rely on the output of the prior task, you'd probably want to use conditionals - something you can do without dropping back to the API.
- ufo 13y agoI know you are nitpicking but the point to using a library or embedded DSL is that you can run completely arbitrary logic inside it. For example, instead of just checking servers to see if they are in the qa_servers list he might have selected the servers that have a name starting with the letter "N" or dynamically fetch a list of server names...
- falcolas 13y agoWith conditional execution, you can do just that. However that is not really the best way to implement the example posited by the OP.