Synbitz Prowduczions
Synbitz Prowduczions

Reputation: 387

Write info about nodes to a CSV file on the controller (the local)

I have written an Ansible playbook that returns some information from various sources. One of the variables I am saving during a task is the number of records in a certain MySQL database table.

I can print out results in the playbook quite well. What I want to do however is write the results from all hosts in a single (csv) file on the master/control server or computer running the playbook

- name: Show results
  debug:
    msg: "URL: {{hostvars[inventory_hostname]['ansible_nodename']}} RECORDCOUNT: {{results.stdout}} BASE VERSION: {{baseversion.stdout}}"

This task prints the info I want for twenty nodes.
I now want to write this line in a single CSV file on the master server.

I've tried various things with local copy but until now to no avail.

Upvotes: 7

Views: 10404

Answers (2)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68339

shell module can come up handy when no other solution visible:

- name: Save results
  shell: echo URL: {{hostvars[inventory_hostname]['ansible_nodename']}} RECORDCOUNT: {{results.stdout}} BASE VERSION: {{baseversion.stdout}} >> /opt/my_file.log
  delegate_to: localhost

Upvotes: 6

Sudarshan V
Sudarshan V

Reputation: 71

This method has issues if the content is too long where your echo error's out. I ended up using the template module.

Just posting here as it may help someone else.

Upvotes: 0

Related Questions