I’ve been using Ansible for more than a year now and it’s great. I mainly use it in playbook mode, and it’s mainly called by the build server as part of a pipeline.
My concern is this: Several times I have gotten stuck when there’s a need for using the output from one command as input to another. This makes it hard to automate flows. I find the Ansible built-in and Jinja filter too limited. With shell, I’m used to working with line-oriented output and piping one cmd to the next. I find that hard to do in Ansible.
Am I the only one with this problem?
Am I missing something?
What are the best practices?
I don’t know Python - is this what’s limiting me?
Can you share your experiences/solutions?
I looked at some threads on this forum and I found some people with similar problems but no general solution. Is it correct that some (specialized) modules return the output as structured data? Could this be added to the basic modules?
Here’s an example:
The first task calls a shell on target host that calls the Tomcat manager on localhost which lists the web apps. A output line looks like this:
/MyWebApp:running:0:MyWebApp
After that I would like to create a list of the running webapps and use this in the following command.
- name: Get running services
local_action: shell getRunningServices {{ inventory_hostname }}
register: validate_int_result
- name: Echo running services
local_action: command echo “Service - {{ item }}”
with_items: validate_int_result.stdout_lines
when: “‘:running:’ in item”
Here the second task only identifies the relevant lines. How do I do what I need to do, i.e. collect the running services into a list variable?