| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- ---
- - name: "Update /etc/hosts with most recent info; for Prod and dev systems"
- hosts: all
- gather_facts: True
- become: true
- tasks:
- - name: "msg print to stdout: Debug ansible_facts"
- debug:
- msg:
- # - "{{ ansible_facts.service_mgr }}"
- - ansible_facts.distribution "{{ ansible_facts.distribution }}"
- - ansible_facts.distribution_major_version "{{ ansible_facts.distribution_major_version }}"
- - ansible_facts.distribution_file_variety "{{ ansible_facts.distribution_file_variety }}"
- - ansible_system "{{ ansible_system }}"
- - name: "Modify an already modified hosts file in a DEV environment"
- lineinfile:
- path: /etc/hosts
- search_string: 'monitoring'
- line: "10.***CONTENTS REDACTED*** monitoring.***CONTENTS REDACTED***"
- when:
- - ansible_system == "Linux"
- - ansible_ansible_all_ipv4_addresses is search("***CONTENTS REDACTED***") or ansible_all_ipv4_addresses is search("***CONTENTS REDACTED***") or ansible_all_ipv4_addresses is search("***CONTENTS REDACTED***")
- - name: "Modify an already modified hosts file in PRODUCTION"
- lineinfile:
- path: /etc/hosts
- search_string: 'monitoring'
- line: "***CONTENTS REDACTED*** monitoring.***CONTENTS REDACTED***"
- state: absent
- when:
- - ansible_system == "Linux"
- - ansible_ansible_all_ipv4_addresses is not search("10.***CONTENTS REDACTED***")
- - ansible_all_ipv4_addresses is not search("10.***CONTENTS REDACTED***")
- - ansible_all_ipv4_addresses is not search("10.***CONTENTS REDACTED***")
- # Restart systemd service
- - name: restart zabbix-agent2.service; systemd
- systemd:
- name: zabbix-agent
- enabled: True
- masked: no
- state: restarted
- ignore_errors: true
- when: ansible_facts.service_mgr == "systemd"
- - name: restart zabbix-agent2.service; systemd
- systemd:
- name: zabbix-agent2
- enabled: True
- masked: no
- state: restarted
- ignore_errors: true
- when: ansible_facts.service_mgr == "systemd"
|