diff --git a/defaults/main.yml b/defaults/main.yaml similarity index 100% rename from defaults/main.yml rename to defaults/main.yaml diff --git a/meta/main.yml b/meta/main.yaml similarity index 100% rename from meta/main.yml rename to meta/main.yaml diff --git a/tasks/main.yaml b/tasks/main.yaml new file mode 100644 index 0000000..3523ffe --- /dev/null +++ b/tasks/main.yaml @@ -0,0 +1,95 @@ +--- + +- name: Load variables + ansible.builtin.include_vars: "{{ ansible_facts['os_family'] }}.yaml" + +- name: Verify variables + ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" + vars: + params: + files: + - "{{ ansible_facts['distribution'] }}_verify_vars.yaml" + - "{{ ansible_facts['os_family' }}_verify_vars.yaml" + - "verify_vars.yaml" + +- name: Install sudo + ansible.builtin.package: + name: "{{ item }}" + state: present + with_items: "{{ sudo_users_package_names }}" + +- name: Enable includedir directive + ansible.builtin.lineinfile: + dest: /etc/sudoers + state: present + regexp: "^(#)+(\\s)*includedir(\\s)*/etc/sudoers.d" + line: "#includedir /etc/sudoers.d" + validate: 'visudo --check --file %s' + mode: "0440" + owner: "root" + group: "root" + +- name: Flush drop-in files of sudoers.d + ansible.builtin.file: + state: "{{ item }}" + path: "/etc/sudoers.d" + owner: "root" + group: "root" + mode: "0750" + with_items: + - absent + - directory + +- name: "Create sudoers drop-in file to execute commands for specific unix users" + community.general.sudoers: + name: "{{ item.filename | default(item.user) }}" + state: present + user: "{{ item.user }}" + nopassword: "{{ item.nopassword | default(false) }}" + commands: "{{ item.commands | default('ALL') }}" + with_items: + - "{{ sudo_users_sudoers }}" + when: item.user is defined and item.user | length > 0 and + item.group is not defined and + item.runas is not defined + +- name: "Create sudoers drop-in file to execute commands for specific unix users as specific unix user" + community.general.sudoers: + name: "{{ item.filename | default(item.user) }}" + state: present + user: "{{ item.user }}" + runas: "{{ item.runas }}" + nopassword: "{{ item.nopassword | default(false) }}" + commands: "{{ item.commands | default('ALL') }}" + with_items: + - "{{ sudo_users_sudoers }}" + when: item.user is defined and item.user | length > 0 and + item.group is not defined and + item.runas is defined and item.runas | length > 0 + +- name: "Create sudoers drop-in file to execute commands for specific unix groups" + community.general.sudoers: + name: "{{ item.filename | default(item.group) }}" + state: present + group: "{{ item.group }}" + nopassword: "{{ item.nopassword | default(false) }}" + commands: "{{ item.commands | default('ALL') }}" + with_items: + - "{{ sudo_users_sudoers }}" + when: item.user is not defined and + item.group is defined and item.group | length > 0 and + item.runas is not defined + +- name: "Create sudoers drop-in file to execute commands for specific unix groups as specifix unix user" + community.general.sudoers: + name: "{{ item.filename | default(item.group) }}" + state: present + group: "{{ item.group }}" + runas: "{{ item.runas }}" + nopassword: "{{ item.nopassword | default(false) }}" + commands: "{{ item.commands | default('ALL') }}" + with_items: + - "{{ sudo_users_sudoers }}" + when: item.user is not defined and + item.group is defined and item.group | length > 0 and + item.runas is defined and item.runas | length > 0 diff --git a/tasks/main.yml b/tasks/main.yml index a8ea7fe..3523ffe 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,16 +1,16 @@ --- - name: Load variables - ansible.builtin.include_vars: "{{ ansible_facts['os_family'] }}.yml" + ansible.builtin.include_vars: "{{ ansible_facts['os_family'] }}.yaml" - name: Verify variables ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" vars: params: files: - - "{{ ansible_facts['distribution'] }}_verify_vars.yml" - - "{{ ansible_facts['os_family' }}_verify_vars.yml" - - "verify_vars.yml" + - "{{ ansible_facts['distribution'] }}_verify_vars.yaml" + - "{{ ansible_facts['os_family' }}_verify_vars.yaml" + - "verify_vars.yaml" - name: Install sudo ansible.builtin.package: diff --git a/tasks/verify_vars.yml b/tasks/verify_vars.yaml similarity index 100% rename from tasks/verify_vars.yml rename to tasks/verify_vars.yaml diff --git a/vars/Archlinux.yml b/vars/Archlinux.yaml similarity index 100% rename from vars/Archlinux.yml rename to vars/Archlinux.yaml diff --git a/vars/Debian.yml b/vars/Debian.yaml similarity index 100% rename from vars/Debian.yml rename to vars/Debian.yaml diff --git a/vars/RedHat.yml b/vars/RedHat.yaml similarity index 100% rename from vars/RedHat.yml rename to vars/RedHat.yaml