简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM