Skip to content

Instantly share code, notes, and snippets.

@robin-checkmk
Created August 17, 2022 08:09
Show Gist options
  • Save robin-checkmk/619bcb13831a77b6e1170c8c17bd17af to your computer and use it in GitHub Desktop.
Save robin-checkmk/619bcb13831a77b6e1170c8c17bd17af to your computer and use it in GitHub Desktop.
yt.yml from the Checkmk Ansible collection introduction
- name: "Roles."
hosts: localhost
gather_facts: true
vars_files:
- ./vars/config.yml
tasks:
- name: "Run server role."
ansible.builtin.import_role:
name: tribe29.checkmk.server
- name: "Run agent role."
ansible.builtin.import_role:
name: tribe29.checkmk.agent
- name: "Pause."
ansible.builtin.pause:
prompt: |
"Press <Enter> to continue."
- name: "Modules."
hosts: test
gather_facts: false
vars_files:
- ./vars/config.yml
tasks:
- name: "Activate changes on site - Showcase no changes."
tribe29.checkmk.activation:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
force_foreign_changes: true
sites:
- "{{ site }}"
delegate_to: localhost
run_once: true
- name: "Create folders."
tribe29.checkmk.folder:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
path: "{{ item.path }}"
title: "{{ item.title }}"
state: "present"
delegate_to: localhost
run_once: true
loop: "{{ checkmk_folders }}"
- name: "Create host."
tribe29.checkmk.host:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
host_name: "{{ inventory_hostname }}"
folder: "{{ checkmk_folder_path }}"
attributes:
site: "{{ site }}"
ipaddress: 127.0.0.1
state: "present"
delegate_to: localhost
- name: "Discover services on host."
tribe29.checkmk.discovery:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
host_name: "{{ inventory_hostname }}"
state: "fix_all"
delegate_to: localhost
- name: "Activate changes on site - Showcase creation of hosts and folders."
tribe29.checkmk.activation:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
force_foreign_changes: true
sites:
- "{{ site }}"
delegate_to: localhost
run_once: true
- name: "Pause."
ansible.builtin.pause:
prompt: |
"Press <Enter> to continue."
- name: "Delete Host."
tribe29.checkmk.host:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
host_name: "{{ inventory_hostname }}"
folder: "{{ checkmk_folder_path }}"
state: "absent"
delegate_to: localhost
when: not inventory_hostname == "localhost"
- name: "Delete folders."
tribe29.checkmk.folder:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
path: "{{ item.path }}"
title: "{{ item.title }}"
state: "absent"
register: testout
delegate_to: localhost
run_once: true
loop: "{{ checkmk_folders }}"
- name: "Activate changes on site - Showcase host and folders were deleted"
tribe29.checkmk.activation:
server_url: "{{ server_url }}"
site: "{{ site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
force_foreign_changes: true
sites:
- "{{ site }}"
delegate_to: localhost
run_once: true
@robin-checkmk
Copy link
Author

robin-checkmk commented Aug 17, 2022

And here is the inventory file you need to create:

hosts

[test]
test1.tld checkmk_folder_path="/test" 
test2.tld checkmk_folder_path="/foo" 
test3.tld checkmk_folder_path="/bar" 
test4.tld checkmk_folder_path="/" 
test5.tld checkmk_folder_path="/foo" 
test6.tld checkmk_folder_path="/bar" 
test7.tld checkmk_folder_path="/" 
test8.tld checkmk_folder_path="/test" 
test9.tld checkmk_folder_path="/bar" 
test10.tld checkmk_folder_path="/foo"

And the vars file:

./vars/config.yml

---
# Modules
server_url: "http://localhost/"
site: "local"
automation_user: "automation"
automation_secret: "SECRET"

checkmk_folders:
  - path: /test
    title: Test
  - path: /foo
    title: Foo
  - path: /bar
    title: Bar

# Agent role
checkmk_agent_version: "2.1.0p9"
checkmk_agent_edition: cre
checkmk_agent_protocol: http
checkmk_agent_server: localhost
checkmk_agent_site: local
checkmk_agent_user: "{{ automation_user | default('automation') }}"
checkmk_agent_pass: "{{ automation_secret }}"
checkmk_agent_update: 'true'
checkmk_agent_tls: 'true'
checkmk_agent_configure_firewall: 'false'
checkmk_agent_prep_legacy: 'false'
checkmk_agent_add_host: 'true'
checkmk_agent_discover: 'false'
checkmk_agent_delegate_api_calls: localhost

# Server Role
checkmk_server_edition: cre
checkmk_server_version: 2.1.0p9
checkmk_server_verify_setup: 'true'
checkmk_server_configure_firewall: 'false'


checkmk_server_sites:
  - name: local
    version: "{{ checkmk_server_version }}"
    state: started
    admin_pw: cmk
    update_conflict_resolution: install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment