tpotce/installer/install/sudo.yml

54 lines
1.6 KiB
YAML
Raw Normal View History

2023-06-21 21:21:11 +00:00
---
#######################################
# T-Pot - Debian Bootstrapping (sudo) #
#######################################
# Be sure to use root password as become password
- name: T-Pot - Debian Bootstrapping (sudo)
2023-06-21 21:21:11 +00:00
hosts: all
gather_facts: false
2023-06-30 11:15:30 +00:00
become: false
2023-06-21 21:21:11 +00:00
tasks:
- name: Check if running as root
assert:
that: ansible_user != 'root'
fail_msg: "T-Pot playbook should not be run as root."
success_msg: "Running as user: {{ ansible_user }}."
tags:
- "Debian"
2023-06-21 21:21:11 +00:00
- name: Check if running as tpot
assert:
that: ansible_user != 'tpot'
fail_msg: "Reserved username `tpot` detected."
success_msg: "Running as user: {{ ansible_user }}."
tags:
- "Debian"
- name: Get distribution name
raw: awk -F= '/^NAME/{print $2}' /etc/os-release | tr -d '"' | cut -d " " -f1
register: my_distribution
tags:
- "Debian"
- name: Check if sudo is installed
# Use echo, or task will fail if sudo not found
raw: echo -n $(command -v sudo)
register: my_sudo
tags:
- "Debian"
2023-06-21 21:21:11 +00:00
- name: Add sudo package and add ansible_user to sudo group (Debian)
2023-06-21 21:21:11 +00:00
become: true
become_method: su
raw: |
apt update
apt -y install sudo
/usr/sbin/usermod -aG sudo {{ ansible_user }}
echo '{{ ansible_user }} ALL=(ALL:ALL) ALL' | tee /etc/sudoers.d/{{ ansible_user }}
chmod 440 /etc/sudoers.d/{{ ansible_user }}
when: my_distribution.stdout | trim in ["Debian"] and my_sudo.stdout | trim == ""
tags:
- "Debian"