You've already forked ansible-role-checkmk-agent
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a49fcd4daa | |||
| 88ca870490 | |||
| 09ec245d1f | |||
| c0b796162c | |||
| 9cafba2e24 | |||
| 8f0116e5a9 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
__pycache__
|
__pycache__
|
||||||
|
*.secrets
|
||||||
|
*.vars
|
||||||
@@ -47,6 +47,9 @@ cmk_secret: some-secret
|
|||||||
# Combined string required for unattended actions
|
# Combined string required for unattended actions
|
||||||
cmk_auth: '&_username={{ cmk_username }}&_secret={{ cmk_secret }}'
|
cmk_auth: '&_username={{ cmk_username }}&_secret={{ cmk_secret }}'
|
||||||
|
|
||||||
|
# Complete API URL
|
||||||
|
cmk_api_url: "{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/1.0"
|
||||||
|
|
||||||
# This variable is used to detect whether this is a fresh install
|
# This variable is used to detect whether this is a fresh install
|
||||||
# Is changed to true if check-mk-agent gets installed
|
# Is changed to true if check-mk-agent gets installed
|
||||||
cmk_fresh_install: false
|
cmk_fresh_install: false
|
||||||
@@ -55,6 +58,6 @@ cmk_fresh_install: false
|
|||||||
# CheckMK is already installed.
|
# CheckMK is already installed.
|
||||||
# Breaks idempotence but allows role to be used to force upgrade agents.
|
# Breaks idempotence but allows role to be used to force upgrade agents.
|
||||||
cmk_force_install: false
|
cmk_force_install: false
|
||||||
cmk_host_ip: '{{ ansible_host }}'
|
#cmk_host_ip: ""
|
||||||
cmk_dl_needs_auth: true
|
cmk_dl_needs_auth: true
|
||||||
cmk_debug: true
|
cmk_debug: true
|
||||||
|
|||||||
@@ -4,13 +4,14 @@
|
|||||||
vars:
|
vars:
|
||||||
cmk_rpm_agent: https://files.cybercinch.nz/agents/check-mk/linux/check-mk-agent-2.2.0p9-1102045deb7cb781.noarch.rpm
|
cmk_rpm_agent: https://files.cybercinch.nz/agents/check-mk/linux/check-mk-agent-2.2.0p9-1102045deb7cb781.noarch.rpm
|
||||||
cmk_dl_needs_auth: false
|
cmk_dl_needs_auth: false
|
||||||
cmk_add_host: false
|
cmk_add_host: true
|
||||||
cmk_download_mode: inline
|
cmk_download_mode: inline
|
||||||
cmk_omd_protocol: "{{ lookup('env', 'CMK_OMD_PROTOCOL')}}"
|
cmk_omd_protocol: "{{ lookup('env', 'CMK_OMD_PROTOCOL')}}"
|
||||||
cmk_omd_host: "{{ lookup('env', 'CMK_OMD_HOST')}}"
|
cmk_omd_host: "{{ lookup('env', 'CMK_OMD_HOST')}}"
|
||||||
cmk_omd_site: "{{ lookup('env', 'CMK_OMD_SITE')}}"
|
cmk_omd_site: "{{ lookup('env', 'CMK_OMD_SITE')}}"
|
||||||
cmk_username: "{{ lookup('env', 'CMK_USERNAME')}}"
|
cmk_username: "{{ lookup('env', 'CMK_USERNAME')}}"
|
||||||
cmk_secret: "{{ lookup('env', 'CMK_SECRET')}}"
|
cmk_secret: "{{ lookup('env', 'CMK_SECRET')}}"
|
||||||
|
cmk_host_ip: "172.16.33.4"
|
||||||
tasks:
|
tasks:
|
||||||
- name: Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}
|
- name: Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}
|
||||||
include_role:
|
include_role:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ dependency:
|
|||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
platforms:
|
platforms:
|
||||||
- name: check_mk_agent-test-${MOLECULE_DISTRO:-almalinux8}
|
- name: check-mk-agent-test-${MOLECULE_DISTRO:-almalinux8}
|
||||||
image: cybercinch/docker-${MOLECULE_DISTRO:-almalinux8}-ansible:latest
|
image: cybercinch/docker-${MOLECULE_DISTRO:-almalinux8}-ansible:latest
|
||||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -5,26 +5,28 @@
|
|||||||
headers:
|
headers:
|
||||||
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
|
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
url: '{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/1.0/domain-types/host_config/collections/all'
|
url: '{{ cmk_api_url }}/domain-types/host_config/collections/all'
|
||||||
body:
|
body:
|
||||||
folder: "{{ cmk_folder | default('~Unsorted') }}"
|
folder: "{{ cmk_folder | default('~Unsorted') }}"
|
||||||
host_name: '{{ inventory_hostname | upper }}'
|
host_name: '{{ inventory_hostname | upper }}'
|
||||||
attributes:
|
attributes:
|
||||||
tag_criticality: prod
|
tag_criticality: prod
|
||||||
tag_agent: cmk-agent
|
tag_agent: cmk-agent
|
||||||
ipaddress: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
|
ipaddress: "{{ cmk_host_ip | default(hostvars[inventory_hostname]['ansible_default_ipv4']['address'], true) }}"
|
||||||
body_format: json
|
body_format: json
|
||||||
return_content: true
|
return_content: true
|
||||||
status_code: [200, 400]
|
status_code: [200, 400]
|
||||||
register: res
|
register: res_add
|
||||||
become: false
|
become: false
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: >
|
when: >
|
||||||
cmk_add_host and cmk_major | int >= 2 and cmk_minor | int >= 2
|
cmk_add_host and cmk_major | int >= 2 and cmk_minor | int >= 2
|
||||||
|
|
||||||
- name: Parse result
|
- name: Parse result
|
||||||
set_fact:
|
set_fact:
|
||||||
output: '{{ res.content | from_json }}'
|
output: '{{ res_add.content | from_json }}'
|
||||||
when: cmk_add_host
|
when: cmk_add_host
|
||||||
|
|
||||||
- name: Host exists fetch etag (new) # noqa command-instead-of-module
|
- name: Host exists fetch etag (new) # noqa command-instead-of-module
|
||||||
shell: |
|
shell: |
|
||||||
curl \
|
curl \
|
||||||
@@ -35,22 +37,22 @@
|
|||||||
--header "Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}" \
|
--header "Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}" \
|
||||||
--header "Accept: application/json" \
|
--header "Accept: application/json" \
|
||||||
"{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/v0/objects/host_config/{{ inventory_hostname | upper }}"
|
"{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/v0/objects/host_config/{{ inventory_hostname | upper }}"
|
||||||
register: res
|
register: res_host_exists
|
||||||
become: false
|
become: false
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: >
|
when: >
|
||||||
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
|
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
|
||||||
(output.status == 400 and output.fields.host_name | first | regex_search('already
|
(res_add.status == 400 and output.fields.host_name | first | regex_search('already
|
||||||
exists.$'))
|
exists.$'))
|
||||||
- debug:
|
|
||||||
var: res
|
|
||||||
- name: Unpick response
|
- name: Unpick response
|
||||||
set_fact:
|
set_fact:
|
||||||
etag: "{{ res.stdout | regex_search('.*etag:.\"(?P<etag>.+)\".*', '\\g<etag>') | first }}"
|
etag: "{{ res_host_exists.stdout | regex_search('.*etag:.\"(?P<etag>.+)\".*', '\\g<etag>') | first }}"
|
||||||
when: >
|
when: >
|
||||||
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
|
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
|
||||||
(output.status == 400 and output.fields.host_name | first | regex_search('already
|
(res_add.status == 400 and output.fields.host_name | first | regex_search('already
|
||||||
exists.$'))
|
exists.$'))
|
||||||
|
|
||||||
- name: Update host as already exists? (new)
|
- name: Update host as already exists? (new)
|
||||||
uri:
|
uri:
|
||||||
method: PUT
|
method: PUT
|
||||||
@@ -71,22 +73,24 @@
|
|||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: >
|
when: >
|
||||||
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
|
cmk_add_host and (cmk_major | int >= 2 and cmk_minor | int >= 2) and
|
||||||
(output.status == 400 and output.fields.host_name | first | regex_search('already
|
(res_add.status == 400 and output.fields.host_name | first | regex_search('already
|
||||||
exists.$'))
|
exists.$'))
|
||||||
|
|
||||||
- name: Parse result
|
- name: Parse result
|
||||||
set_fact:
|
set_fact:
|
||||||
output: '{{ res.content | from_json }}'
|
output: '{{ res_add.content | from_json }}'
|
||||||
when: cmk_add_host
|
when: cmk_add_host
|
||||||
|
|
||||||
- name: cmk_discovery (new)
|
- name: cmk_discovery (new)
|
||||||
uri:
|
uri:
|
||||||
method: POST
|
method: POST
|
||||||
headers:
|
headers:
|
||||||
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
|
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
url: '{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/1.0/domain-types/service_discovery_run/actions/start/invoke'
|
url: '{{ cmk_api_url }}/domain-types/service_discovery_run/actions/start/invoke'
|
||||||
body:
|
body:
|
||||||
host_name: '{{ inventory_hostname | upper }}'
|
host_name: '{{ inventory_hostname | upper }}'
|
||||||
mode: refresh
|
mode: fix_all
|
||||||
body_format: json
|
body_format: json
|
||||||
status_code: [200, 302]
|
status_code: [200, 302]
|
||||||
become: false
|
become: false
|
||||||
@@ -95,21 +99,25 @@
|
|||||||
cmk_minor | int >= 2 or
|
cmk_minor | int >= 2 or
|
||||||
cmk_force_install
|
cmk_force_install
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: cmk_apply (new)
|
- name: cmk_apply (new)
|
||||||
uri:
|
uri:
|
||||||
method: POST
|
method: POST
|
||||||
headers:
|
headers:
|
||||||
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
|
Authorization: Bearer {{ cmk_username }} {{ cmk_secret }}
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
url: '{{ cmk_omd_protocol }}://{{ cmk_omd_host }}/{{ cmk_omd_site }}/check_mk/api/1.0/domain-types/activation_run/actions/activate-changes/invoke'
|
If-Match: "*"
|
||||||
|
url: '{{ cmk_api_url }}/domain-types/activation_run/actions/activate-changes/invoke'
|
||||||
body:
|
body:
|
||||||
redirect: 'False'
|
redirect: false
|
||||||
sites: ['{{ cmk_omd_site }}']
|
sites:
|
||||||
force_foreign_changes: 'False'
|
- "{{ cmk_omd_site }}"
|
||||||
|
force_foreign_changes: false
|
||||||
body_format: json
|
body_format: json
|
||||||
status_code: 200
|
status_code: 200
|
||||||
become: false
|
become: false
|
||||||
run_once: true
|
run_once: true
|
||||||
when: >
|
when: >
|
||||||
cmk_add_host and cmk_major | int >= 2 and cmk_minor | int >= 2 and cmk_force_install
|
cmk_add_host and cmk_major | int >= 2 and
|
||||||
|
cmk_minor | int >= 2 or cmk_force_install
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|||||||
@@ -12,6 +12,6 @@
|
|||||||
# Register for automatic agent updates
|
# Register for automatic agent updates
|
||||||
- include_tasks: '{{ ansible_os_family }}-register.yml'
|
- include_tasks: '{{ ansible_os_family }}-register.yml'
|
||||||
when: cmk_fresh_install
|
when: cmk_fresh_install
|
||||||
# Finalize things and collect all available services
|
# # Finalize things and collect all available services
|
||||||
- include_tasks: host-configure.yml
|
# - include_tasks: host-configure.yml
|
||||||
when: cmk_fresh_install
|
# when: cmk_fresh_install
|
||||||
|
|||||||
Reference in New Issue
Block a user