I've build a lovely set of Ansible playbooks that are used by packer to build our Linux images for software builds in AWS. They're so nice that now a bunch of other teams want to use them too.
The current setup is a playbook that calls a lot of roles. Some of those roles do system level config and others create the user defined by the var jenkins_user and set up various programs for it (conan, npm, jfrog)
Since my roles are already set up to act on a single variable, it should not be too difficult to modify them to act on an array of usernames. I'm trying to decide on the best approach of defining the multiple users.
I'll need a small number of vars for each user:
- username
- password
- private key
- authorized keys file
I'm trying to decide the best way to store all this. My first thought is a hash of users and data:
build_users:
user1:
password: "{{vault_user1_pass}}"
private_key_file: "{{vault_user1_key}}"
auth_keys_file: "{{auth_keys_file}}"
user2:
password: "{{vault_user2_pass}}"
private_key_file: "{{vault_user2_key}}"
auth_keys_file: "{{user2_auth_keys_file}}"
This would have me gatekeeping user data, which isn't necessarily a bad thing.
The second thing I thought of was just to have a directory with each user in their own file: user1.yml contains
user1:
password: "{{vault_user1_pass}}"
private_key_file: "{{vault_user1_key}}"
auth_keys_file: "{{auth_keys_file}}"
then user2.yml contains
user2:
password: "{{vault_user2_pass}}"
private_key_file: "{{vault_user2_key}}"
auth_keys_file: "{{user2_auth_keys_file}}"
However, it seems that if I try to add additional files to the buildusers variable, include_vars overwrites it instead of adding:
- name: load buildusers files
include_vars:
dir: buildusers
name: buildusers
This results in the buildusers variable only having the last files data in it.
buildusers
resulting inuser1
andusers2
members of thebuildusers
hash, and similarly any other users that are included. They will collide if you don't have unique values in the top level of each file, though. – gaige