DavidWittman/ansible-redis

Why check if redis user exists?

eRadical opened this issue · 1 comments

What is the rationale behing checking for user existence?

- name: check if redis user exists (ignore errors)
command: id {{ redis_user }}
ignore_errors: yes
changed_when: false
register: user_exists
- name: add redis group
group:
name: "{{ redis_group }}"
state: present
when: user_exists|failed
- name: add redis user
user:
name: "{{ redis_user }}"
group: "{{ redis_group }}"
comment: "Redis"
home: "{{ redis_install_dir }}"
shell: /bin/false
system: yes
when: user_exists|failed

The when clause from user creation should simply go away.

Instead of interpreting it as "make user redis if not exists" that should be read/seen as "make sure user redis exists"... more inclined to the state of things rather than action.

Same goes for the redis group which is now checked through the existence of the user.

[Would be glad to make a pull request on this but I wanted to see if there is any rationale that I missed.]

I haven't looked at this in a while, but I think the logic here was to prevent changes to an already existing redis user. If you look at the original commit there's mention of a failure when running usermod in that case.