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>
19 lines
595 B
YAML
19 lines
595 B
YAML
---
|
|
|
|
- name: "Check if the skel file exists: /etc/skel/{{ skel_file }}"
|
|
ansible.builtin.stat:
|
|
path: "/etc/skel/{{ skel_file }}"
|
|
register: _unix_users_skel_file
|
|
|
|
# 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 }}"
|
|
dest: "{{ user_user_home }}/{{ skel_file }}"
|
|
remote_src: true
|
|
force: false
|
|
owner: "{{ unix_user.key }}"
|
|
group: "{{ unix_user.value.group | default('users') }}"
|
|
mode: "0644"
|
|
when: _unix_users_skel_file.stat.exists
|