-
Notifications
You must be signed in to change notification settings - Fork 4
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
Manage SSH key via 'debops.authorized_keys' role #15
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e734114
Manage SSH key via 'debops.authorized_keys' role
ganto e2a8f3b
Fix inventory group name
ganto 89f86e1
Fix typo
ganto 5e1c71c
Move host fact lookup to key definition
ganto 3146772
Only query host facts if server group and host is found
ganto cac0bfd
Fix typo in 'authorized_keys__dependent_list' definition
ganto ed18b97
Don't try to create root user
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
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
This file was deleted.
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.
@drybjed: what do you think of this? Is there a way how you implemented something like this more elegant?
somehow the
hostvars[groups["debops_service_checkmk_server"]]
expression will trigger a deprecation warning in case the group is not defined in the inventory.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.
It's
sshkeys
. I don't think that you need to lookup keys in local facts. If you specify emptysshkeys
, role should just skip management of the keys. So, defining onlycheckmk_agent__user_key
variable in inventory should be enough.And here, just set it like this:
That should do what you expect, although I would test it first to be sure.
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.
The point is, that they key is generated during the setup of the monitoring site. If the user has to specify this manually, it would abort the playbook run, then the user has to lookup they key manually. Or he need to generate a keypair in advance and configure them before running the server setup.
I wish to find a solution where the setup just works. See also debops-contrib/ansible-checkmk_server#15
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.
For this you will probably want to split the role into normal and "env" role (from "environment"). It would work like this:
That way you can prepare data for other roles that need it, hand it off to the other roles and return back to managing your application. For an example, check the debops.php role and its example playbook.
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.
@drybjed I don't see what problem this is going to solve.
Is this bad practice to lookup a service provider in the host facts? This code is functional and behaves as intended, just that it emits a deprecation warning, in case no
debops_service_checkmk_service
group has been defined.I will move it to the variable definition of
checkmk_agent__user_key
then the code will become a bit easier to read.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.
What deprecated warning, about Undefined variable? This will be error in the future, you need to fix that.
Moving the lookup code to the variable is good, then users can modify it if they wish without the need to modify the role itself.
As for the 'role/env' solution - this comes from a pretty specific design principles of DebOps roles - they are supposed to be read-only, and you should pass configuration of other roles through default variables. In specific situations, like generating data on a host by your role, or using lookup templates, you might find that Ansible does not have the data it needs at this specific point in the playbook, or it does the lookup in the wrong role.
In the given
debops.php
example, the role checks what PHP package versions are available and then acts on that information, however another role,debops.logrotate
is also using this information to generate the correctlogrotate
configuration for thephp-fpm
service. The information about PHP version is stored in a variable, however onlydebops.php
sets this variable. Sincedebops.logrotate
is supposed to run beforedebops.php
, it would not know beforehand what PHP version it should use to generate the config file. Basically a casuality violation. :-)To resolve this, I decided to split the
debops.php
role essentially into two - first one,debops.php/env
contains minimum amount of tasks to "set the environment" for other roles - it checks what PHP versions are available, and even configures external APT repositories. When its tasks are done, other roles likedebops.logrotate
can act on variables passed throughdebops.php
defaults since the required facts are set in the memory. After that,debops.php
continues as usual to finish the configuration.As I said, this is a very situational solution and you won't need this with the most roles. However, I suggested it here since you mentioned that the SSH keys on the specific hosts are generated by the role. To avioid the need to run the playbook twice to complete the configuration, you can do it like this:
checkmk_server/env
generates the SSH keys and slurps them into memorydebops.authorized_keys
configures the SSH keys using data fromcheckmk_server
defaults + SSH keyscheckmk_server
finishes the configurationThis should keep things clean and consistent.