TLDR
I want the users on our infrastructure to reflect exactly the configuration files (json) that I provide to ansible.
A fast and simple approach would then be:
- delete all users
- recreate all users
but that means that at each deployment, the users will disappear for a moment, this must be avoided! A better approach would probably be:
- list all users on the infracture
- create the missing users
- update all users (make sure they use the latest configuration found in the json files)
- delete all other users
While I can probably implement this manually, this seems rather cumbersome. Is there an easier way of implementing this with ansible?
Long story
We are using ansible
to configure our infrastructure. When creating users for example, the main task would look like this:
- name: import users
uri:
url: "{{ '%(url)s/users/user/%(user)s'|format(
url=url,
user=user
) }}"
method: PUT
user: "{{ configuration_user }}"
password: "{{ configuration_password }}"
force_basic_auth: yes
body_format: json
body: "{{ lookup('template', item) }}"
status_code: 200, 201
vars:
user: "{{ item | basename | regex_replace('.json','') }}"
with_fileglob:
- security/users/*.json
So we are just using the PUT
method to create/update the users. Difficulties with this approach:
- the infrastructure must provide a create/update method (
PUT
orPOST
with overwrite option or something similar) - when a user is deleted, and we delete the corresponding json file, running the ansible script again won't delete that user.