Hello,

I have posted the following at 
https://stackoverflow.com/questions/62309274/how-to-have-ansible-send-output-to-a-python-function-in-a-custom-library,
 
but I wanted to share here to get some more insight.

I am a newbie at working with Ansible and Python and I am attempting to 
develop an Ansible playbook that will query several Cisco ASR5500's running 
current iOS software for CLI output of various show commands. I would like 
to take that output and send it to a python function in a custom library 
which will apply logic to see if the response from the ASR shows that it is 
healthy or not. Currently, I am sending the Ansible output to a file with 
the thought of having Python read the file and analyze each line. Here is a 
snippet from my playbook:

- name: show card table         # run "show card table" on node
  ios_command:
    commands:
      - show card table
  register: output_cardTable- name: send output_cardTable to file         # 
send "show card table" to file
  lineinfile:
    dest: /home/**my_user**/testoutput/{{ inventory_hostname }}_{{ my_time }}
    line: "{{ output_cardTable.stdout_lines }}"
    insertafter: EOF

This snippet takes the output of "show card table" and sends it to a 
timestamped file as a multi-dimensional array (not sure why it's formatted 
like that, but that's another question for later). My first thought was to 
have Ansible run the checks and then have Python read the generated files 
for each node and apply its logic to determine the node's health.


However, I would like to know if there is a way for Ansible to send the 
output of the task directly to a function in a imported Python library, 
similar to how RobotFramework can invoke a Python function from a library 
that has been declared. I do not know if such syntax exists, but Ansible is 
better at maintaining connections to multiple nodes concurrently, and 
RobotFramework is not the tool of choice for my organization.


So, how would I write the task that sends the "output_cardTable" content to 
a python function, and how would I declare that function library in the 
header of the playbook so Ansible can see and use it?


Any insight would be appreciated. Thank you.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6df3edc0-ac47-4c4d-92de-1ca1eadcd722o%40googlegroups.com.

Reply via email to