made use of username of user logged in and running 'sudo' for particular tasks, added true 'become' attrbute to some tasks
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
#SPDX-License-Identifier: MIT-0
|
||||
---
|
||||
# tasks file for roles/init-vps
|
||||
- name: Acquiring current user
|
||||
when: ansible_facts["system"] == "Linux"
|
||||
ansible.builtin.shell:
|
||||
cmd: "echo {{ ansible_user }}"
|
||||
register: current_user
|
||||
- name: Checking whether administrative login used
|
||||
when: ansible_user not in (admins | map(attribute="username") | list) and ansible_user != "root"
|
||||
ansible.builtin.fail:
|
||||
msg: Must use administrative user for subsequent tasks
|
||||
- name: Hardening SSH service
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
src: sshd_config.d/harden.conf
|
||||
dest: /etc/ssh/sshd_config.d/harden.conf
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
---
|
||||
# tasks file for roles/init-vps
|
||||
# @TODO complete below tasks
|
||||
- name: Acquiring current user
|
||||
when: ansible_facts["system"] == "Linux"
|
||||
ansible.builtin.shell:
|
||||
cmd: "echo {{ ansible_user }}"
|
||||
register: current_user
|
||||
- name: Checking whether administrative login used
|
||||
when: ansible_user not in (admins | map(attribute="username") | list)
|
||||
ansible.builtin.fail:
|
||||
@@ -46,8 +51,6 @@
|
||||
when: ansible_facts["system"] == "Linux"
|
||||
become: true
|
||||
ansible.builtin.blockinfile:
|
||||
# src: sshd_config.d/sftp.conf.j2
|
||||
# dest: /etc/ssh/sshd_config.d/sftp.conf
|
||||
path: /etc/ssh/sshd_config.d/sftp.conf
|
||||
block: |
|
||||
Match Group {{ item.name }}
|
||||
|
||||
Reference in New Issue
Block a user