Here is the whole playbook:
tasks:
- name: cat /etc/yum.conf
shell: cat /etc/yum.conf
register: proxy
tags:
- YUM
- name: check if repo files exists
stat:
path: "{{ zabbix_repo }}"
register: zabbix_exists
tags:
- YUM
- CHECK
- name: "install 8 if not exists (proxy)"
dnf:
name: "{{ zabbix_8 }}"
state: latest
disable_gpg_check: yes
ignore_errors: true
environment: "{{ proxy_env }}"
when:
- ansible_distribution_major_version is version('8', '=')
- zabbix_exists.stat.exists == False
- ansible_default_ipv4.address is match('192\.168\.226\.') or
ansible_default_ipv4.address is match('10\.172\.226\.')
tags:
- PROXY
- YUM
- name: "install 8 if not exists (noproxy)"
dnf:
name: "{{ zabbix_8 }}"
state: latest
disable_gpg_check: yes
ignore_errors: true
when:
- ansible_distribution_major_version is version('8', '=')
- zabbix_exists.stat.exists == False
- ansible_default_ipv4.address is match('192\.168\.224\.') or
ansible_default_ipv4.address is match('192\.168\.223\.') or
ansible_default_ipv4.address is match('192\.168\.225\.') or
ansible_default_ipv4.address is match('192\.168\.227\.') or
ansible_default_ipv4.address is match('192\.168\.228\.') or
ansible_default_ipv4.address is match('192\.168\.223\.')
- name: "install 7 if not exists (proxy)"
yum:
name: "{{ zabbix_7 }}"
state: latest
disable_gpg_check: yes
ignore_errors: true
environment: "{{ proxy_env }}"
when:
- ansible_distribution_major_version is version('7', '=')
- zabbix_exists.stat.exists == False
- ansible_default_ipv4.address is match('
ansible_default_ipv4.address is match('10\.172\.226\.')
tags:
- PROXY
- YUM
- name: "install 7 if not exists (noproxy)"
yum:
name: "{{ zabbix_7 }}"
state: latest
disable_gpg_check: yes
ignore_errors: true
when:
- ansible_distribution_major_version is version('7', '=')
- zabbix_exists.stat.exists == False
- ansible_default_ipv4.address is match('192\.168\.224\.') or
ansible_default_ipv4.address is match('192\.168\.223\.') or
ansible_default_ipv4.address is match('192\.168\.225\.') or
ansible_default_ipv4.address is match('192\.168\.227\.') or
ansible_default_ipv4.address is match('192\.168\.228\.') or
ansible_default_ipv4.address is match('192\.168\.224\.') or
ansible_default_ipv4.address is match('192\.168\.223\.')
- name: "install 6 if not exists (proxy)"
yum:
name: "{{ zabbix_6 }}"
state: latest
ignore_errors: true
environment: "{{ proxy_env }}"
when:
- ansible_distribution_major_version is version('6', '=')
- zabbix_exists.stat.exists == False
- ansible_default_ipv4.address is match('192\.
ansible_default_ipv4.address is match('10\.172\.226\.')
tags:
- YUM
- name: "install 6 if not exists (no proxy)"
yum:
name: "{{ zabbix_6 }}"
state: latest
ignore_errors: true
when:
- ansible_distribution_major_version is version('6', '=')
- zabbix_exists.stat.exists == False
- ansible_default_ipv4.address is match('192\.168
\.224\.') or
ansible_default_ipv4.address is match('192
\.168
\.223\.') or
ansible_default_ipv4.address is match('192
\.168
\.225\.') or
ansible_default_ipv4.address is match('192
\.168
\.227\.') or
ansible_default_ipv4.address is match('192
\.168
\.228\.') or
ansible_default_ipv4.address is match('192\.168\.224\.') or
ansible_default_ipv4.address is match('192\.168\.223\.')
tags:
- YUM
- name: add proxy to zabbix.repo if needed
lineinfile:
path: /etc/yum.repos.d/zabbix.repo
regexp: 'proxy'
state: present
line: 'proxy=http://proxy:8080'
insertafter: '\[zabbix\]'
when:
- ansible_default_ipv4.address is match('192
\.168\.226\.') or
ansible_default_ipv4.address is match('10\.172\.226\.')
tags:
- YUM
- name: Change http to https
replace:
path: /etc/yum.repos.d/zabbix.repo
regexp: 'http:'
replace: 'https:'
tags:
- HTTPS
- name: Install zabbix-agent
yum:
name: zabbix-agent
state: latest
ignore_errors: true
- name: Check firewalld
firewalld:
port: 10050/tcp
permanent: true
state: enabled
when:
- ansible_distribution_major_version is version('7', '=') or
ansible_distribution_major_version is version('8', '=')
notify: restart firewalld
- name: Output iptables
shell: iptables -L -n
register: iptables_rules
tags: IPTABLES
- name: Check iptables
iptables:
chain: INPUT
source: 192.168.224.240/32
protocol: tcp
destination_port: 10050
jump: ACCEPT
when:
- ansible_distribution_major_version is version('6', '=')
- iptables_rules.find("10050") == -1
notify:
- iptables save
- restart iptables
tags: IPTABLES
- name: Update server
lineinfile:
path: "{{ zabbix_config }}"
regexp: '^Server\=127.0.0.1'
line: 'Server=atsb-pup-svr-lx'
notify: restart zabbix
- name: comment out hostname
lineinfile:
path: "{{ zabbix_config }}"
regexp: '^Hostname\='
line: '#Hostname='
notify: restart zabbix
- name: uncomment HostnameItem
lineinfile:
path: "{{ zabbix_config }}"
regexp: '^#\ HostnameItem.*'
line: 'HostnameItem=system.hostname'
notify: restart zabbix
- name: Enable on boot and start
service:
name: zabbix-agent
state: started
enabled: yes
- name: Upgrade zabbix yum repo
block:
- name: cat /etc/yum.conf
shell: cat /etc/yum.conf
register: upgrade_proxy
- name: Upgrade RHEL7 Zabbix Yum BES
yum:
name: "{{ zabbix_7 }}"
state: latest
when:
- ansible_distribution_major_version is version('7', '=')
- ansible_default_ipv4.address is match('192\.168\.224\.') or
ansible_default_ipv4.address is match('192
\.168
\.223\.') or
ansible_default_ipv4.address is match('192
\.168
\.227\.') or
ansible_default_ipv4.address is match('192
\.168
\.228\.') or
ansible_default_ipv4.address is match('192\.168\.224\.') or
ansible_default_ipv4.address is match('192\.168\.223\.')
- name: Upgrade RHEL6 Zabbix Yum BES
yum:
name: "{{ zabbix_6 }}"
state: latest
when:
- ansible_distribution_major_version is version('6', '=')
- ansible_default_ipv4.address is match('192\.168
\.224\.') or
ansible_default_ipv4.address is match('192
\.168
\.223\.') or
ansible_default_ipv4.address is match('192
\.168
\.227\.') or
ansible_default_ipv4.address is match('192
\.168
\.228\.') or
ansible_default_ipv4.address is match('192\.168\.224\.') or
ansible_default_ipv4.address is match('192\.168\.223\.')
- name: Upgrade RHEL7 Zabbix Yum NCS
yum:
name: "{{ zabbix_7 }}"
state: latest
environment: "{{ proxy_env }}"
when:
- ansible_distribution_major_version is version('7', '=')
- ansible_default_ipv4.address is match('192\.168\.226\.') or
ansible_default_ipv4.address is match('10\.172\.226\.')
- name: Upgrade RHEL6 Zabbix Yum NCS
yum:
name: "{{ zabbix_6 }}"
state: latest
environment: "{{ proxy_env }}"
when:
- ansible_distribution_major_version is version('6', '=')
- ansible_default_ipv4.address is match('192\.168\.226\.') or
ansible_default_ipv4.address is match('10\.172\.226\.')
- name: Change http to https
replace:
path: /etc/yum.repos.d/zabbix.repo
regexp: 'http:'
replace: 'https:'
tags:
- HTTPS
notify: yum clean all
- name: add proxy to zabbix.repo for NCS systems
lineinfile:
path: /etc/yum.repos.d/zabbix.repo
regexp: 'proxy'
state: present
line: 'proxy=http://proxy:8080'
insertafter: '\[zabbix\]'
when:
- upgrade_proxy.stdout.find('proxy') != -1
- name: Upgrade zabbix-agent
yum:
name: zabbix-agent
state: latest
notify: restart zabbix
tags: never
handlers:
- name: restart zabbix
service:
name: zabbix-agent
state: restarted
- name: restart firewalld
service:
name: firewalld
state: restarted
- name: iptables save
command: iptables-save > /etc/sysconfig/iptables
tags: IPTABLES
- name: restart iptables
service:
name: iptables
state: restarted
tags: IPTABLES
- name: yum clean all
shell: yum clean all