|
| 1 | +--- |
| 2 | +- name: "Showcase dcd module." |
| 3 | + hosts: test |
| 4 | + strategy: linear |
| 5 | + gather_facts: false |
| 6 | + vars_files: |
| 7 | + - ../vars/auth.yml # This vars file provides details about your site |
| 8 | + - ../vars/folders.yml # This vars file contains the folders to manage |
| 9 | + - ../vars/dcd.yml # This vars file contains the groups to manage |
| 10 | + tasks: |
| 11 | + # - name: "Gather Date and Time Facts on localhost." |
| 12 | + # ansible.builtin.setup: |
| 13 | + # gather_subset: |
| 14 | + # - date_time |
| 15 | + # delegate_to: localhost |
| 16 | + # run_once: true # noqa run-once[task] |
| 17 | + |
| 18 | + - name: "Create folders." |
| 19 | + folder: |
| 20 | + server_url: "{{ checkmk_var_server_url }}" |
| 21 | + site: "{{ checkmk_var_site }}" |
| 22 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 23 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 24 | + path: "{{ item.path }}" |
| 25 | + name: "{{ item.name }}" |
| 26 | + state: "present" |
| 27 | + delegate_to: localhost |
| 28 | + run_once: true # noqa run-once[task] |
| 29 | + loop: "{{ checkmk_var_folders }}" |
| 30 | + |
| 31 | + - name: "Create hosts." |
| 32 | + host: |
| 33 | + server_url: "{{ checkmk_var_server_url }}" |
| 34 | + site: "{{ checkmk_var_site }}" |
| 35 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 36 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 37 | + name: "{{ inventory_hostname }}" |
| 38 | + folder: "{{ checkmk_var_folder_path }}" |
| 39 | + attributes: |
| 40 | + site: "{{ checkmk_var_site }}" |
| 41 | + ipaddress: 127.0.0.1 |
| 42 | + state: "present" |
| 43 | + delegate_to: localhost |
| 44 | + |
| 45 | + - name: "Create DCD Configuration." |
| 46 | + dcd: |
| 47 | + server_url: "{{ checkmk_var_server_url }}" |
| 48 | + site: "{{ checkmk_var_site }}" |
| 49 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 50 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 51 | + dcd_config: "{{ item }}" |
| 52 | + state: "present" |
| 53 | + loop: "{{ checkmk_var_dcd }}" |
| 54 | + run_once: true # noqa run-once[task] |
| 55 | + delegate_to: localhost |
| 56 | + |
| 57 | + - name: "Pause to review changes." # noqa name[unique] |
| 58 | + ansible.builtin.pause: |
| 59 | + prompt: | |
| 60 | + "Feel free to review the changes in your Checkmk site: {{ checkmk_var_site }}." |
| 61 | + "Press <Enter> to continue." |
| 62 | + when: not checkmk_var_run_unattended | bool |
| 63 | + |
| 64 | + - name: "Activate changes on site." # noqa name[unique] |
| 65 | + activation: |
| 66 | + server_url: "{{ checkmk_var_server_url }}" |
| 67 | + site: "{{ checkmk_var_site }}" |
| 68 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 69 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 70 | + force_foreign_changes: 'true' |
| 71 | + sites: |
| 72 | + - "{{ checkmk_var_site }}" |
| 73 | + delegate_to: localhost |
| 74 | + run_once: true # noqa run-once[task] |
| 75 | + |
| 76 | + - name: "Delete DCD Configuration." |
| 77 | + dcd: |
| 78 | + server_url: "{{ checkmk_var_server_url }}" |
| 79 | + site: "{{ checkmk_var_site }}" |
| 80 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 81 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 82 | + dcd_config: "{{ item }}" |
| 83 | + state: "absent" |
| 84 | + loop: "{{ checkmk_var_dcd }}" |
| 85 | + run_once: true # noqa run-once[task] |
| 86 | + delegate_to: localhost |
| 87 | + |
| 88 | + - name: "Delete Hosts." |
| 89 | + host: |
| 90 | + server_url: "{{ checkmk_var_server_url }}" |
| 91 | + site: "{{ checkmk_var_site }}" |
| 92 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 93 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 94 | + name: "{{ inventory_hostname }}" |
| 95 | + folder: "{{ checkmk_var_folder_path }}" |
| 96 | + state: "absent" |
| 97 | + delegate_to: localhost |
| 98 | + |
| 99 | + - name: "Delete folders." |
| 100 | + folder: |
| 101 | + server_url: "{{ checkmk_var_server_url }}" |
| 102 | + site: "{{ checkmk_var_site }}" |
| 103 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 104 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 105 | + path: "{{ item.path }}" |
| 106 | + name: "{{ item.name }}" |
| 107 | + state: "absent" |
| 108 | + delegate_to: localhost |
| 109 | + run_once: true # noqa run-once[task] |
| 110 | + loop: "{{ checkmk_var_folders }}" |
| 111 | + |
| 112 | + - name: "Pause to review changes." # noqa name[unique] |
| 113 | + ansible.builtin.pause: |
| 114 | + prompt: | |
| 115 | + "Feel free to review the changes in your Checkmk site: {{ checkmk_var_site }}." |
| 116 | + "Press <Enter> to continue." |
| 117 | + when: not checkmk_var_run_unattended | bool |
| 118 | + |
| 119 | + - name: "Activate changes on site." # noqa name[unique] |
| 120 | + activation: |
| 121 | + server_url: "{{ checkmk_var_server_url }}" |
| 122 | + site: "{{ checkmk_var_site }}" |
| 123 | + automation_user: "{{ checkmk_var_automation_user }}" |
| 124 | + automation_secret: "{{ checkmk_var_automation_secret }}" |
| 125 | + force_foreign_changes: 'true' |
| 126 | + sites: |
| 127 | + - "{{ checkmk_var_site }}" |
| 128 | + delegate_to: localhost |
| 129 | + run_once: true # noqa run-once[task] |
0 commit comments