fix(tasks): repair the never executed skel file copy
The task guarded itself with `_skel_file.stat.exist`, but the stat module returns `exists`. The `is defined` check on the misspelled attribute therefore always evaluated to false and the whole task was silently skipped, so no skel file was ever copied into a home directory. Two further defects surfaced once the guard was corrected. The source path interpolated the registered result dict `_skel_file` instead of the loop variable `skel_file`, and the copy module read from the control node because `remote_src` was missing, so `/etc/skel` of the managed host was never consulted. The stat now probes the source instead of the destination. Distributions ship different skel files, for example Debian has no `.bash_profile`, and copying a non existing remote source would abort the run. The "only copy when absent" behaviour is delegated to `force: false`, which the copy module implements natively. The register variable is prefixed with the role name so it can no longer be confused with the loop variable. The mode is corrected to 0644, the mode `/etc/skel` uses for its dotfiles. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
---
|
||||
|
||||
- name: "Exist file {{ skel_file }}"
|
||||
- name: "Check if the skel file exists: /etc/skel/{{ skel_file }}"
|
||||
ansible.builtin.stat:
|
||||
path: "{{ user_user_home }}/{{ skel_file }}"
|
||||
register: _skel_file
|
||||
path: "/etc/skel/{{ skel_file }}"
|
||||
register: _unix_users_skel_file
|
||||
|
||||
- name: Copy skel file
|
||||
when: _skel_file.stat is defined and
|
||||
_skel_file.stat.exist is defined and
|
||||
not _skel_file.stat.exist
|
||||
# force: false keeps an already customized dotfile in the home directory untouched.
|
||||
- name: "Copy skel file: {{ skel_file }}"
|
||||
ansible.builtin.copy:
|
||||
src: "/etc/skel/{{ _skel_file }}"
|
||||
src: "/etc/skel/{{ skel_file }}"
|
||||
dest: "{{ user_user_home }}/{{ skel_file }}"
|
||||
remote_src: true
|
||||
force: false
|
||||
owner: "{{ unix_user.key }}"
|
||||
group: "{{ unix_user.value.group | default('users') }}"
|
||||
mode: "0600"
|
||||
mode: "0644"
|
||||
when: _unix_users_skel_file.stat.exists
|
||||
|
||||
Reference in New Issue
Block a user