fix(webadmin-user.yml): update inventory checks and standardize variable names for clarity

This commit is contained in:
2026-07-29 17:53:55 +02:00
parent e72d9aac70
commit fea739f0e6
+46 -44
View File
@@ -12,7 +12,7 @@
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
when: when:
- groups['webadmin']|string is search(inventory_hostname) - inventory_hostname in (groups['webadmin'] | default([]))
- webadmin_user is defined - webadmin_user is defined
- item.group_id is defined - item.group_id is defined
tags: tags:
@@ -33,14 +33,14 @@
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
when: when:
- groups['webadmin']|string is search(inventory_hostname) - inventory_hostname in (groups['webadmin'] | default([]))
- webadmin_user is defined - webadmin_user is defined
tags: tags:
- webadmin - webadmin
- users-exists - users-exists
- name: (webadmin-user.yml) Ensure authorized_key files for webadmin user is present - name: (webadmin-user.yml) Ensure authorized_key files for webadmin user is present
authorized_key: ansible.posix.authorized_key:
user: "{{ item.0.name }}" user: "{{ item.0.name }}"
key: "{{ item.1 }}" key: "{{ item.1 }}"
state: present state: present
@@ -51,7 +51,7 @@
label: "{{ item.0.name }} key: {{ idx + 1 }}" label: "{{ item.0.name }} key: {{ idx + 1 }}"
index_var: idx index_var: idx
when: when:
- groups['webadmin']|string is search(inventory_hostname) - inventory_hostname in (groups['webadmin'] | default([]))
- webadmin_user is defined - webadmin_user is defined
tags: tags:
- webadmin - webadmin
@@ -64,7 +64,7 @@
owner: "{{ item.login }}" owner: "{{ item.login }}"
group: "{{ item.login }}" group: "{{ item.login }}"
mode: "0600" mode: "0600"
#when: groups['oopen_server']|string is search(inventory_hostname) # when: groups['oopen_server']|string is search(inventory_hostname)
when: when:
- insert_webadmin_ssh_keypair|bool - insert_webadmin_ssh_keypair|bool
with_items: "{{ webadmin_ssh_keypair }}" with_items: "{{ webadmin_ssh_keypair }}"
@@ -105,9 +105,9 @@
# devel-repos contains SVN repositiries; webadmin must have ssh access to # devel-repos contains SVN repositiries; webadmin must have ssh access to
# to webadmin at devel-repos to manage SVN repository # to webadmin at devel-repos to manage SVN repository
# #
- name: (webadmin-user.yml) Ensure authorized_key on devel-repos hosts contains public key - name: (webadmin-user.yml) Ensure authorized_key on devel-repos hosts contains public key
authorized_key: ansible.posix.authorized_key:
user: "{{ item.login }}" user: "{{ item.login }}"
key: "{{ lookup('file', item.pub_key_src) }}" key: "{{ lookup('file', item.pub_key_src) }}"
state: present state: present
@@ -125,45 +125,46 @@
# --- # ---
- name: (users-systemfiles.yml) Check if local template directory exists for webadmin - name: (users-systemfiles.yml) Check if local template directory exists for webadmin
ansible.builtin.stat: path={{ inventory_dir }}/files/homedirs/{{ item.name }} ansible.builtin.stat:
path: "{{ inventory_dir }}/files/homedirs/{{ item.name }}"
delegate_to: localhost delegate_to: localhost
with_items: "{{ webadmin_user }}" with_items: "{{ webadmin_user }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
register: local_template_dir_webadmin register: common_local_template_dir_webadmin
# -- # --
# Copy .bashrc # Copy .bashrc
# --- # ---
#- name: (webadmin-user.yml) Check if webadmin's file '.bashrc.ORIG' exists # - name: (webadmin-user.yml) Check if webadmin's file '.bashrc.ORIG' exists
# stat: # stat:
# path: "~{{ item.item.name }}/.bashrc.ORIG" # path: "~{{ item.item.name }}/.bashrc.ORIG"
# register: bashrc_webadmin_orig_exists # register: common_bashrc_webadmin_orig_exists
# with_items: "{{ local_template_dir_webadmin.results }}" # with_items: "{{ common_local_template_dir_webadmin.results }}"
# loop_control: # loop_control:
# label: '{{ item.item.name }}' # label: '{{ item.item.name }}'
# when: # when:
# - item.stat.exists # - item.stat.exists
# tags: # tags:
# - webadmin # - webadmin
# - bash # - bash
# #
#- name: (webadmin-user.yml) Backup existing webadmin's .bashrc file # - name: (webadmin-user.yml) Backup existing webadmin's .bashrc file
# command: cp ~{{ item.item.item.name }}/.bashrc ~{{ item.item.item.name }}/.bashrc.ORIG # command: cp ~{{ item.item.item.name }}/.bashrc ~{{ item.item.item.name }}/.bashrc.ORIG
# loop: "{{ bashrc_webadmin_orig_exists.results }}" # loop: "{{ common_bashrc_webadmin_orig_exists.results }}"
# loop_control: # loop_control:
# label: '{{ item.item.item.name }}' # label: '{{ item.item.item.name }}'
# when: # when:
# - item.stat.exists == False # - item.stat.exists
# tags: # tags:
# - webadmin # - webadmin
# - bash # - bash
- name: (webadmin-user.yml) Check if webadmin's file '.bashrc.ORIG' exists - name: (webadmin-user.yml) Check if webadmin's file '.bashrc.ORIG' exists
ansible.builtin.stat: ansible.builtin.stat:
path: "~{{ item.name }}/.bashrc.ORIG" path: "~{{ item.name }}/.bashrc.ORIG"
register: bashrc_webadmin_orig_exists register: common_bashrc_webadmin_orig_exists
with_items: "{{ webadmin_user }}" with_items: "{{ webadmin_user }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
@@ -172,12 +173,12 @@
- bash - bash
- name: (webadmin-user.yml) Backup existing webadmin's .bashrc file - name: (webadmin-user.yml) Backup existing webadmin's .bashrc file
ansible.builtin.command: cp -a ~{{ item.item.name }}/.bashrc ~{{ item.item.name }}/.bashrc.ORIG ansible.builtin.command:
loop: "{{ bashrc_webadmin_orig_exists.results }}" cmd: cp -a ~{{ item.item.name }}/.bashrc ~{{ item.item.name }}/.bashrc.ORIG
creates: "~{{ item.item.name }}/.bashrc.ORIG"
loop: "{{ common_bashrc_webadmin_orig_exists.results }}"
loop_control: loop_control:
label: "{{ item.item.name }}" label: "{{ item.item.name }}"
when:
- item.stat.exists == False
tags: tags:
- webadmin - webadmin
- bash - bash
@@ -206,7 +207,7 @@
- name: (webadmin-user.yml) Check if webadmin's file '.profile.ORIG' exists - name: (webadmin-user.yml) Check if webadmin's file '.profile.ORIG' exists
ansible.builtin.stat: ansible.builtin.stat:
path: "~{{ item.name }}/.profile.ORIG" path: "~{{ item.name }}/.profile.ORIG"
register: profile_webadmin_orig_exists register: common_profile_webadmin_orig_exists
with_items: "{{ webadmin_user }}" with_items: "{{ webadmin_user }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
@@ -215,12 +216,12 @@
- profile - profile
- name: (webadmin-user.yml) Backup existing users .profile file - name: (webadmin-user.yml) Backup existing users .profile file
ansible.builtin.command: cp -a ~{{ item.item.name }}/.profile ~{{ item.item.name }}/.profile.ORIG ansible.builtin.command:
with_items: "{{ profile_webadmin_orig_exists.results }}" cmd: cp -a ~{{ item.item.name }}/.profile ~{{ item.item.name }}/.profile.ORIG
creates: "~{{ item.item.name }}/.profile.ORIG"
with_items: "{{ common_profile_webadmin_orig_exists.results }}"
loop_control: loop_control:
label: "{{ item.item.name }}" label: "{{ item.item.name }}"
when:
- item.stat.exists == False
tags: tags:
- webadmin - webadmin
- profile - profile
@@ -263,10 +264,11 @@
- webadmin - webadmin
- vim - vim
- name: (webadmin-user.yml) Check if local template directory .vim exists for webadmin - name: (webadmin-user.yml) Check if local template directory .vim exists for webadmin
ansible.builtin.stat: path={{ inventory_dir }}/files/homedirs/webadmin/.vim ansible.builtin.stat:
path: "{{ inventory_dir }}/files/homedirs/webadmin/.vim"
delegate_to: localhost delegate_to: localhost
register: local_template_dir_vim_webadmin register: common_local_template_dir_vim_webadmin
with_items: "{{ webadmin_user }}" with_items: "{{ webadmin_user }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
@@ -278,7 +280,7 @@
owner: "{{ item.item.name }}" owner: "{{ item.item.name }}"
group: "{{ item.item.name }}" group: "{{ item.item.name }}"
mode: "0644" mode: "0644"
with_items: "{{ local_template_dir_vim_webadmin.results }}" with_items: "{{ common_local_template_dir_vim_webadmin.results }}"
loop_control: loop_control:
label: "{{ item.item.name }}" label: "{{ item.item.name }}"
when: when: