Use sudo/become instead of root directly #158

Open
samsapti wants to merge 2 commits from use_sudo into main
5 changed files with 11 additions and 10 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ playbook.retry
*.log
.idea/
venv/
/ansible.cfg

View file

@ -1,4 +1,10 @@
init: create_venv install_pre_commit install_ansible_galaxy_modules
init: create_ansible_cfg create_venv install_pre_commit install_ansible_galaxy_modules
.ONESHELL:
create_ansible_cfg:
read -rp "Enter remote username: " REMOTE_USER
cp ansible.cfg.sample ansible.cfg
sed -i "s/REMOTE_USER/$$REMOTE_USER/g" ansible.cfg
create_venv:
python3 -m venv venv
@ -9,4 +15,4 @@ install_pre_commit:
venv/bin/pre-commit install
install_ansible_galaxy_modules:
venv/bin/ansible-galaxy collection install community.general
venv/bin/ansible-galaxy collection install community.general

View file

@ -1,4 +1,4 @@
[defaults]
remote_user = root
remote_user = REMOTE_USER
inventory = datacoop_hosts
use_persistent_connections = True

View file

@ -8,7 +8,7 @@ usage () {
} >&2
}
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass"
BASE_CMD="ansible-playbook playbook.yml --ask-become-pass --ask-vault-pass"
if [ "$1" = "--vagrant" ]; then
BASE_CMD="$BASE_CMD --verbose --inventory=vagrant_host"

View file

@ -15,9 +15,3 @@
key: "{{ item.ssh_keys | join('\n') }}"
exclusive: true
loop: "{{ users | default([]) }}"
- name: "Add ssh authorized_keys to root user"
ansible.posix.authorized_key:
user: "root"
key: "{{ users | default([]) | map(attribute='ssh_keys') | flatten | join('\n') }}"
exclusive: true