-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Complete rework of the role to simplify distributed site setup #53
Open
ganto
wants to merge
34
commits into
debops-contrib:master
Choose a base branch
from
ganto:distributed-rework
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
5075df2
Remove unneeded variables
ganto 66259aa
Add current status of site creation
ganto ee665af
Fix 'multisite_password', set required 'multisite_alias'
ganto 7b8dbc2
Set credential paths related to the inventory name instead of fqdn
ganto 821688e
Convert user setup to run for distributed sites in 'checkmk_servers__…
ganto 21a2bfa
Iterate user setup tasks over all distributed sites
ganto 2954cc2
Make distributed site login and config work with new site definition
ganto 231d06e
Remove unused variables
ganto 9128633
Create new env sub-role for site setup, write site facts
ganto 3ea7723
Adjust home that it matches the user created by 'omd'
ganto 333b001
Use user__dependent_accounts and etc_services__dependent_list from facts
ganto 6b8fd58
Make sure the checkmk_server/env tasks are run by all play hosts
ganto 1737762
Leverage ssh key setup from debops.users role, set public key local fact
ganto 81f078a
Read correct facts after changes, add SSH authorized_keys setup
ganto a726abf
Add users to 'sshusers' group which allows SSH login
ganto 81810fd
Run config synchronization to slave site via rsync
ganto e51f79f
Update playbook to use the 'checkmk_server/env' and 'debops.users' roles
ganto 0d0a2fb
Rename 'checkmk_server__hostname' to 'checkmk_server__fqdn' for consi…
ganto 5b01f6c
Fix applying custom patches, remove env role debugging
ganto bae1222
Leverage 'debops.apache' role for local reverse proxy configuration
ganto 53c1e53
Explicitly define Apache configuration includes provided by Check_MK
ganto 97aceb8
Remove HTTP-related ferm rules now handled by 'apache__ferm__dependen…
ganto 1924a7a
Generate ferm rules for livestatus according to the configured sites
ganto 5635218
Fix 'apache__dependent_snippets' configuration
ganto b2c4951
Remove some debugging code
ganto af9d305
Define dependent vars in defaults, don't fail with no facts
ganto cdfb4e3
Run tests on Ubuntu trusty as precise is EOL
ganto c5717d4
Create master site if 'checkmk_server__site' is defined
ganto 35bc317
Don't fail if 'mod_headers' is not (yet) enabled
ganto e641ae7
Properly set and update local facts from the correct context
ganto 5bc3e41
Adjust the fact that local facts are stored as dict not lists
ganto 5c0a5da
Adjust SSH public key lookup to new facts layout
ganto 6a5c4f5
Update dependency to Ansible >=2.3.0
ganto 4d0e8ca
Clarify comments in the local facts template
ganto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
|
||
sudo: True | ||
sudo: required | ||
dist: trusty | ||
language: 'python' | ||
python: '2.7' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../defaults |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Author: Reto Gantenbein <[email protected]> | ||
Date: Tue Jun 21 06:51:23 2016 +0200 | ||
Date: Tue May 8 17:57:28 2017 +0200 | ||
|
||
Set X-Forwarded headers when accessed via HTTPS | ||
|
||
|
@@ -14,15 +14,21 @@ Date: Tue Jun 21 06:51:23 2016 +0200 | |
%{SERVER_PORT} in in the X-Forwarded-Port header | ||
failed because it seemed to be undefined "(null)". | ||
|
||
v2: - Guard 'RequestHeader' statements with | ||
<IfModule> to avoid errors if mod_headers | ||
is not (yet) enabled | ||
|
||
--- /omd/versions/default/skel/etc/apache/apache-own.conf.orig 2016-05-13 19:19:07.000000000 +0200 | ||
+++ /omd/versions/default/skel/etc/apache/apache-own.conf 2016-06-21 06:50:03.169171120 +0200 | ||
@@ -11,6 +11,10 @@ | ||
+++ /omd/versions/default/skel/etc/apache/apache-own.conf 2017-05-08 17:56:25.342383031 +0200 | ||
@@ -11,6 +11,12 @@ | ||
ProxyRequests Off | ||
ProxyPreserveHost On | ||
|
||
+ # Indicate when the site was accessed via HTTPS | ||
+ <IfModule mod_headers.c> | ||
+ RequestHeader set X-Forwarded-Proto https env=HTTPS | ||
+ RequestHeader set X-Forwarded-Port 443 env=HTTPS | ||
+ </IfModule> | ||
+ | ||
# Include file created by 'omd config', which | ||
# sets the TCP port of the site local webserver | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
# IMPORTANT: | ||
# These tasks are run for each Check_MK site defined | ||
# in `checkmk_server__sites`. This means they can run multiple | ||
# times per server. If the monitoring site is a remote slave, | ||
# they might even run on a different server. The site configuration | ||
# is available through `site_item`. | ||
|
||
- name: Create Check_MK site | ||
command: omd create '{{ site_item.name }}' | ||
args: | ||
creates: '{{ site_item.home }}/etc/omd/site.conf' | ||
delegate_to: '{{ site_item.delegate_to | ||
if (not site_item.delegate_to == inventory_hostname) else omit }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
# | ||
# Set site facts so that later tasks can depend on it | ||
# | ||
# IMPORTANT: | ||
# These tasks are run for each Check_MK site defined | ||
# in `checkmk_server__sites`. This means they can run multiple | ||
# times per server. If the monitoring site is a remote slave, | ||
# they might even run on a different server. The site configuration | ||
# is available through `site_item`. | ||
|
||
- name: Persist site facts | ||
block: | ||
|
||
- name: Make sure that local fact directory exists | ||
file: | ||
dest: '/etc/ansible/facts.d' | ||
state: 'directory' | ||
owner: 'root' | ||
group: 'root' | ||
mode: '0755' | ||
|
||
- name: Save Check_MK server local facts | ||
template: | ||
src: 'etc/ansible/facts.d/checkmk_server.fact.j2' | ||
dest: '/etc/ansible/facts.d/checkmk_server.fact' | ||
owner: 'root' | ||
group: 'root' | ||
mode: '0644' | ||
register: checkmk_server__register_local_facts | ||
|
||
# Delegate entire block to corresponding host | ||
delegate_to: '{{ site_item.delegate_to | ||
if (not site_item.delegate_to == inventory_hostname) else omit }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
- name: Check that involved distributed sites servers are play hosts | ||
assert: | ||
that: checkmk_server__sites | map(attribute="delegate_to") | list | issubset(play_hosts) | ||
msg: 'Make sure that playbook is run on all servers included in distributed sites. Not doing so might result in wrong variable defaults.' | ||
|
||
- name: Install prerequisite packages | ||
apt: | ||
name: '{{ item }}' | ||
state: present | ||
with_items: '{{ checkmk_server__prerequisite_packages }}' | ||
|
||
- name: Check check-mk-raw package version | ||
shell: dpkg-query -W -f='${Version}\n' check-mk-raw-{{ checkmk_server__version }} | cut -d- -f1 | ||
register: checkmk_server__register_version | ||
changed_when: False | ||
failed_when: False | ||
check_mode: no | ||
|
||
- name: Download Check_MK RAW package | ||
get_url: | ||
url: '{{ checkmk_server__raw_package }}' | ||
dest: '/var/cache/apt/archives/{{ checkmk_server__raw_package | basename }}' | ||
register: checkmk_server__register_download | ||
when: (not checkmk_server__register_version.stdout) and | ||
(checkmk_server__raw_package | match('^http')) | ||
|
||
- name: Install local Check_MK RAW package | ||
apt: | ||
deb: '{{ "/var/cache/apt/archives/" + (checkmk_server__raw_package | basename) | ||
if (not checkmk_server__register_download | skipped) | ||
else checkmk_server__raw_package }}' | ||
state: present | ||
register: checkmk_server__register_deb_install | ||
when: (not checkmk_server__register_version.stdout) and | ||
((checkmk_server__raw_package | splitext)[1] == '.deb') | ||
|
||
- name: Install Check_MK RAW package from repository | ||
apt: | ||
name: '{{ checkmk_server__raw_package }}' | ||
state: present | ||
register: checkmk_server__register_apt_install | ||
when: (not checkmk_server__register_version.stdout) and | ||
(not checkmk_server__register_deb_install|d()) | ||
|
||
- name: Apply patches | ||
patch: | ||
src: '{{ item.patch }}' | ||
dest: '{{ item.file }}' | ||
basedir: '/' | ||
with_items: '{{ checkmk_server__patches }}' | ||
when: (checkmk_server__register_apt_install | changed) or | ||
(checkmk_server__register_deb_install | changed) | ||
|
||
- name: Get Check_MK default version | ||
stat: | ||
path: '/omd/versions/default' | ||
register: checkmk_server__register_default | ||
check_mode: no | ||
|
||
- name: Set new default version | ||
command: omd setversion '{{ checkmk_server__version }}{{ checkmk_server__version_suffix }}' | ||
when: (checkmk_server__register_default.stat.lnk_source | | ||
basename) != (checkmk_server__version + checkmk_server__version_suffix) | ||
|
||
- name: Create Check_MK sites | ||
include: create_sites.yml | ||
with_items: '{{ checkmk_server__sites }}' | ||
loop_control: | ||
loop_var: site_item | ||
|
||
- name: Set site facts | ||
include: facts.yml | ||
with_items: '{{ checkmk_server__sites }}' | ||
loop_control: | ||
loop_var: site_item | ||
tags: [ 'role::checkmk_server:facts' ] | ||
|
||
- name: Re-read local facts | ||
action: setup | ||
tags: [ 'role::checkmk_server:facts' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
|
||
- name: Login on remote site | ||
uri: | ||
url: '{{ item.multisite_url }}/login.py' | ||
method: POST | ||
body: '{{ [ "_login=1", | ||
"_username=" + item.multisite_username, | ||
"_password=" + item.multisite_password, | ||
"_origtarget=automation_login.py", | ||
"_plain_error=1" ] | join("&") }}' | ||
force_basic_auth: yes | ||
user: '{{ item.multisite_username }}' | ||
password: '{{ item.multisite_password }}' | ||
status_code: 302 | ||
validate_certs: '{{ not item.multisite_insecure|bool }}' | ||
register: checkmk_server__register_multisite_login | ||
when: (not item.connection|d('remote') == 'local') | ||
with_items: '{{ checkmk_server__sites }}' | ||
|
||
- name: Get Multisite distribution secrets | ||
uri: | ||
url: '{{ item.location }}' | ||
HEADER_Cookie: '{{ item.set_cookie }}' | ||
return_content: True | ||
validate_certs: '{{ item.invocation.module_args.validate_certs }}' | ||
register: checkmk_server__register_multisite_automation_login | ||
no_log: True | ||
when: not item | skipped | ||
with_items: '{{ checkmk_server__register_multisite_login.results | ||
if "results" in checkmk_server__register_multisite_login else [] }}' | ||
|
||
- name: Generate distributed sites configuration | ||
template: | ||
src: 'etc/check_mk/multisite.d/sites.mk.j2' | ||
dest: '{{ item.home }}/{{ checkmk_server__multisite_config_path }}/sites.mk' | ||
owner: '{{ item.user }}' | ||
group: '{{ item.group }}' | ||
when: (item.connection|d('remote') == 'local') | ||
with_items: '{{ checkmk_server__sites }}' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to drop 2.2 support as well? a3a149a does not mention one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, I didn't mention the reason here. Actually, I was bitten by ansible/ansible#14542. Ansible
2.3.0
fixed the issue for me. As mentioned in the linked PR it wasn't fixed in the2.2.x
tree back then and I never tried to find a release who does.2.3.0
is the safe choice. Will update the commit message accordingly.