From 5f194b91d4587e17a25ea6bd02b1ef90e7e2d5ec Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Sat, 11 Apr 2026 02:10:19 +0200 Subject: [PATCH] feat: Move from Debian to Fedora --- .gitignore | 2 +- meta/main.yml | 7 ++++++- tasks/configuration.yml | 21 ++++++++++++++++++++- tasks/installation.yml | 11 ++++++++++- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index fdcf9b4..22f433d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ tags # ---> Ansible *.retry - +.ansible diff --git a/meta/main.yml b/meta/main.yml index c35869f..b07a29d 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -10,6 +10,11 @@ galaxy_info: platforms: - name: Debian versions: - - all + - "bookworm" + - "trixie" + - "sid" + - name: Fedora + versions: + - "43" dependencies: [] diff --git a/tasks/configuration.yml b/tasks/configuration.yml index dd99d29..a99cf8b 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -15,10 +15,24 @@ loop_var: user label: "{{ user.name }}" +- name: Create bash aliases path for Fedora + ansible.builtin.file: + path: "~{{ user.name }}/.bashrc.d/" + state: directory + owner: "{{ user.name }}" + group: "{{ user.group | default(user.name) }}" + mode: u=rwX,g=,o= + when: ansible_facts['distribution'] | lower == "fedora" + become: true + loop: "{{ users }}" + loop_control: + loop_var: user + label: "{{ user.name }}" + - name: Deploy bash_aliases ansible.builtin.template: src: bash_aliases.j2 - dest: "~{{ user.name }}/.bash_aliases" + dest: "{{ users_bash_alias[distribution] }}" owner: "{{ user.name }}" group: "{{ user.group | default(user.name) }}" mode: u=rw,g=,o= @@ -27,6 +41,11 @@ loop_control: loop_var: user label: "{{ user.name }}" + vars: + distribution: "{{ ansible_facts['distribution'] | lower }}" + users_bash_alias: + debian: ~{{ user.name }}/.bash_aliases + fedora: "~{{ user.name }}/.bashrc.d/01-common" - name: Create ssh directory ansible.builtin.file: diff --git a/tasks/installation.yml b/tasks/installation.yml index 8669e49..505173c 100644 --- a/tasks/installation.yml +++ b/tasks/installation.yml @@ -12,7 +12,8 @@ - name: Create groups with the users name ansible.builtin.group: name: "{{ item.name }}" - when: user.group is undefined + state: "{{ item.state | default('present') }}" + when: user.group | default([]) | length == 0 become: true loop: "{{ users }}" loop_control: @@ -21,6 +22,7 @@ - name: Create other groups ansible.builtin.group: name: "{{ item.1 }}" + when: item.state | default('present') == 'present' become: true loop: "{{ users | subelements('groups', skip_missing=True) }}" loop_control: @@ -36,7 +38,14 @@ shell: "{{ item.shell | default(omit) }}" group: "{{ item.group | default(item.name) }}" groups: "{{ item.groups | default(omit) }}" + state: "{{ item.state | default('present') }}" become: true loop: "{{ users }}" loop_control: label: "{{ item.name }}" + +- name: Exclude users to delete + ansible.builtin.set_fact: + users: "{{ users | ansible.builtin.difference(users_to_delete) }}" + vars: + users_to_delete: "{{ users | selectattr('state', 'defined') | selectattr('state', 'equalto', 'absent') }}" -- 2.51.0