Hi,

Ansible version - 2.9

Facing issue in writing output to a csv file, its not writing the output 
consistently into the file.

Having an inventory file with three server IPs,  script will execute 
command to check the disk space of each server and writing the output to a 
csv file.

Sometimes its writing all the three server details into the file, sometimes 
its writing only one or two server details into the file. 

  - hosts: localhost
    connection: local
    gather_facts: False
    vars:
      filext: ".csv"
    tasks:
      - name: get the username running the deploy
        local_action: command whoami
        register: username_on_the_host

      - name: get current dir
        local_action: command pwd
        register: current_dir

      - name: create dir
        file: path={{ current_dir.stdout }}/HCT state=directory

      - name: Set file path here
        set_fact:
            file_path: "{{ current_dir.stdout }}/HCT/HCT_check{{ filext }}"

      - name: Creates file
        file: path={{ file_path }}  state=touch

# Writing to a csv file

    - hosts:
      - masters
    become: false
    vars:
      disk_space: "Able to get disk space for the CM {{ hostname }} "
      disk_space_error: "The server {{ hostname  }} is down for some 
reason. Please check manually."
      disk_space_run_status: "{{disk_space}}"
      cur_date: "{{ansible_date_time.iso8601}}"

    tasks:
      - name: runnig command to get file system which are occupied 
        command: bash -c "df -h | awk '$5>20'"
        register: disk_space_output
        changed_when: false
        ignore_errors: True
        no_log: True

      - name: Log the task get list of file systems with space occupied 
        lineinfile:
           dest: "{{ hostvars['localhost']['file_path'] }}"
           line: "File system occupying disk space, {{ hostname }}, {{ 
ip_address }}, {{ cur_date }}"
           insertafter: EOF
           state: present
        delegate_to: localhost

Please help to resolve this issue.


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/79186368-aa44-423b-b13a-c691269dbcabn%40googlegroups.com.

Reply via email to