Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit c579bdf7 authored by Freezed's avatar Freezed Committed by foobar
Browse files

:sparkles: Add playbooks: become_user_cfg & shutdown

"reset_connection" tip came from:
https://www.jeffgeerling.com/blog/2021/allowing-ansible-playbooks-work-new-user-groups-on-first-run

:passport_control: Remove sudo passwd less add root auth w/ key

Root is accessible from:
 * SSH by key
 * sudo by password

TODO: if keychain is waiting for passphrase, ansible hang
https://www.funtoo.org/Keychain#Quick_Setup
parent e731e539
No related branches found
No related tags found
1 merge request!1Draft: Resolve "Timeout (12s) waiting for privilege escalation prompt:"
......@@ -6,7 +6,7 @@ clean:
find . -type f -name "*.orig" -delete
open_all:
${EDITOR} .gitignore inventory Makefile host_info.yml README.md whoami.yml
${EDITOR} .gitignore become_user_cfg.yml host_info.yml inventory Makefile README.md shutdown.yml whoami.yml
inventory_generation:
cp inventory.sample inventory && ${EDITOR} inventory
......@@ -13,10 +13,12 @@ Suitable for server and workstation.
✨ Features
-----------
| playbook | return |
|-----------------------------------|---------------------------------------------------|
| [`host_info.yml`](host_info.yml) | distribution full name & version |
| [`whoami.yml`](whoami.yml) | `ansible_user` & `become_user` (`sudo` method) |
| playbook | purpose |
| :--------------------------------------: | :--------------------------------------------------------------: |
| [`become_user_cfg.yml`](become_user_cfg.yml) | Set `sudo` without password for `become_user` access |
| [`host_info.yml`](host_info.yml) | Return message with distribution full name & version |
| [`shutdown.yml`](shutdown.yml) | Shutdown target in 10 min |
| [`whoami.yml`](whoami.yml) | Return message with `ansible_user` & `become_user` (`sudo` method) |
🚀 Quickstart
......
---
- hosts: "{{ host_list }}"
become: yes
become_method: sudo
remote_user: "{{ my_user }}"
tasks:
- name: SUDO | Group sudo presence
ansible.builtin.group:
name: sudo
state: present
- name: SUDO | Group wheel absence
ansible.builtin.group:
name: wheel
state: absent
- name: SUDO | User presence (with groups)
ansible.builtin.user:
name: "{{ my_user }}"
state: present
groups: sudo
append: true
- name: SUDO | Reset ansible connection to apply group update
meta: reset_connection
- name: "SSH | Local public key is present for {{ my_user }}"
ansible.builtin.authorized_key:
comment: "Managed by Ansible from GitLab @free_zed"
key: https://gitlab.com/free_zed.keys
state: present
user: "{{ my_user }}"
- name: SSH | Disallow SSH password authentication for root
copy:
src: sshd_config
dest: /etc/ssh/sshd_config
- name: "SSH | Local public key is present for root"
ansible.builtin.authorized_key:
comment: "Managed by Ansible from GitLab @free_zed"
key: https://gitlab.com/free_zed.keys
state: present
user: root
- name: SSH | Remove no password directive
ansible.builtin.lineinfile:
path: /etc/sudoers
state: absent
regexp: 'NOPASSWD'
validate: '/usr/sbin/visudo -cf %s'
---
- hosts: "{{ host_list }}"
remote_user: root
tasks:
- name: Shutdown the host in 10 min
community.general.shutdown:
delay: 600
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment