main.yml 3.41 KB
Newer Older
Adam Robinson's avatar
Adam Robinson committed
1
2
---
# tasks file for configure_vmware_syslog
3
4
5
6
7
8
9
- name: Set log level for hostd
  vmware_host_config_manager:
    hostname: '{{ vcenter_hostname }}'
    esxi_hostname: '{{ inventory_hostname }}'
    username: '{{ vmware_user }}'
    password: '{{ vmware_password }}'
    options:
10
        'Config.HostAgent.log.level': '{{ hostd_log_level }}'
11
12
13
14
15
16
17
18
19
20
21
22
  delegate_to: localhost

- name: Set log level for vpxa
  vmware_host_config_manager:
    hostname: '{{ vcenter_hostname }}'
    esxi_hostname: '{{ inventory_hostname }}'
    username: '{{ vmware_user }}'
    password: '{{ vmware_password }}'
    options:
        'Vpx.Vpxa.config.log.level': '{{ vpxa_log_level }}'
  delegate_to: localhost

Adam Robinson's avatar
Adam Robinson committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
- name: Get the current state of all services
  vmware_host_service_facts:
    hostname: '{{ vcenter_hostname }}'
    esxi_hostname: '{{ inventory_hostname }}'
    username: '{{ vmware_user }}'
    password: '{{ vmware_password }}'
  delegate_to: localhost
  register: host_service_facts

- name: Start SSH Temporarily to configure Syslog Filtering
  vmware_host_service_manager:
    hostname: '{{ vcenter_hostname }}'
    esxi_hostname: '{{ inventory_hostname }}'
    username: '{{ vmware_user }}'
    password: '{{ vmware_password }}'
    service_name: TSM-SSH
    state: start
  delegate_to: localhost
  when: not host_service_facts['host_service_facts'][inventory_hostname] | selectattr('key', 'equalto', 'TSM-SSH') | map(attribute='running') | list | first | bool
  notify: Stop SSH

- name: Enable Syslog Filtering
  ini_file:
    create: no
    backup: yes
    path: /etc/vmsyslog.conf
    section: vmsyslog
    option: enable_logfilters
    value: 'true'
    state: present
  when: configure_syslog_filters|bool
  notify: Reload syslog
  vars:
    ansible_user: '{{ vmware_user }}@{{ ad_domain|upper }}'
    ansible_password: '{{ vmware_password }}'
    ansible_connection: paramiko
    ansible_python_interpreter: /bin/python

- name: Disable Syslog Filtering
  ini_file:
    create: no
    backup: yes
    path: /etc/vmsyslog.conf
    section: vmsyslog
    option: enable_logfilters
    state: absent
  when: not configure_syslog_filters|bool
  notify: Reload syslog
  vars:
    ansible_user: '{{ vmware_user }}@{{ ad_domain|upper }}'
    ansible_password: '{{ vmware_password }}'
    ansible_connection: paramiko
    ansible_python_interpreter: /bin/python

- name: Deploy Syslog Filters Template
  template:
    src: logfilters.j2
    dest: /etc/vmware/logfilters
  when: configure_syslog_filters|bool and (ansible_distribution_version == "6.5.0" or ansible_distribution_version == "6.7.0")
  notify: Reload syslog
  vars:
    ansible_user: '{{ vmware_user }}@{{ ad_domain|upper }}'
    ansible_password: '{{ vmware_password }}'
    ansible_connection: paramiko
    ansible_python_interpreter: /bin/python
    
- name: Set Syslog Host
  vmware_host_config_manager:
    hostname: '{{ vcenter_hostname }}'
    esxi_hostname: '{{ inventory_hostname }}'
    username: '{{ vmware_user }}'
    password: '{{ vmware_password }}'
    options:
        'Syslog.global.logHost': '{{ syslog_servers }}'
  delegate_to: localhost
  when: configure_remote_syslog|bool

- name: Allow syslog through the firewall
  vmware_host_firewall_manager:
    hostname: '{{ vcenter_hostname }}'
    esxi_hostname: '{{ inventory_hostname }}'
    username: '{{ vmware_user }}'
    password: '{{ vmware_password }}'
    rules:
      - name: syslog
        enabled: True
  delegate_to: localhost
  when: configure_remote_syslog|bool