Test ping et win_ping cibles Ansible rapport CSV

Voir aussi :

Ansible Ping ICMP

#!/usr/bin/ansible-playbook --- - name: Test ping hosts: all ignore_unreachable: true gather_facts: false tasks: - name: Set_fact - fichier_csv - random run_once: true set_fact: fichier_csv: "/tmp/ping_result_{{ rand }}.csv" vars: rand: "{{ range(10000, 99999) | random }}" - name: Ansible win_ping ignore_errors: true win_ping: register: r_ping when: os | lower == 'windows' - name: Ansible ping ignore_errors: true ping: register: r_ping when: os | lower != 'windows' - name: setfacts hostname set_fact: field_hostname: "{{ inventory_hostname }}" - name: Create CSV test ping OK delegate_to: localhost lineinfile: path: "{{ fichier_csv }}" create: true mode: "0640" line: >- {{ field_hostname }}; {%- if r_ping.ping is defined -%} {{ r_ping.ping + ';' }} {%- else -%} ; {{ r_ping.msg | replace(';', ',') | regex_replace('\n', ' ') | regex_replace('\r', ' ') + ';' }} {%- endif -%} when: r_ping.ping is defined or r_ping.msg is defined - name: block delegate_to: localhost run_once: true block: - name: find csv register: reg_find_csv find: paths: /tmp/ patterns: "ping_result_*.csv" - name: set_fact - csv_found set_fact: csv_found: "{{ csv_found | d([]) + reg_find_csv.files | map(attribute='path') | list }}" - name: Send mail run_once: true delegate_to: localhost mail: host: smtp.acme.local port: 25 to: me@acme.local subject: CSV ping attach: "{{ csv_found }}" body: >- See attachement.