Compare commits

...

14 Commits

Author SHA1 Message Date
Alex Tavarez
44a292f19f Added password prompt and declared ansible_user variable 2025-10-21 16:39:58 -04:00
Alex Tavarez
f055178030 Moved SSH user configuration from playbook files to lockdown role files 2025-10-21 16:39:00 -04:00
Alex Tavarez
c579cf386b Moved XDG user configuration from playbook files to lockdown role files 2025-10-21 16:38:00 -04:00
Alex Tavarez
3d35228d29 Moved SSH user config example from playbook files to lockdown role file 2025-10-21 16:34:58 -04:00
Alex Tavarez
430db9c1d8 Moved bash aliases and functions from playbook files to lockdown role files 2025-10-21 16:32:46 -04:00
Alex Tavarez
09cdafc570 Added task for taking contents from acquired files, added delegation to a task 2025-10-21 14:07:48 -04:00
Alex Tavarez
fd8e4e29b6 Changed task name for imported playbook 2025-10-21 14:06:38 -04:00
Alex Tavarez
8d4ef1a461 Changed source path for files moved into lockdown role that are used in copy module tasks 2025-10-21 14:05:51 -04:00
Alex Tavarez
8647bb2a06 Made match terms more efficient and less redundant 2025-10-21 14:01:55 -04:00
Alex Tavarez
fa015cd85c Added an example SSH user configuration file for hosts under the servers group 2025-10-21 11:50:21 -04:00
Alex Tavarez
8a77110c0b Fixed indentation, changed destination path basename for copy module tasks 2025-10-21 11:36:41 -04:00
Alex Tavarez
7884ac47cf Refactored git configuration tasks, converting them to lockdown role tasks, and replaced playbook prompt variables with lockdown role variabls 2025-10-21 11:33:44 -04:00
Alex Tavarez
e2c1dcdd2f Added defaults for some git configuration values 2025-10-21 09:28:37 -04:00
Alex Tavarez
66b71ee225 Refactored and moved set of git configuration tasks to lockdown role 2025-10-21 09:20:17 -04:00
13 changed files with 260 additions and 206 deletions

View File

@@ -8,5 +8,9 @@ create_users:
ssh_pubkey_filename_pattern: '.*\.pub' ssh_pubkey_filename_pattern: '.*\.pub'
include_root_lock: yes include_root_lock: yes
gpg_private_keys_origin_host: localhost gpg_private_keys_origin_host: localhost
ssh_keypairs_origin_host: localhost
gpg_origin_private_keyids: [] # @NOTE list of gpg key ids from origin or source server gpg_origin_private_keyids: [] # @NOTE list of gpg key ids from origin or source server
gpg_origin_private_key_passwords: "{{ vaulted_gpg_origin_private_key_passwords }}" # @NOTE list of gpg key passwords from origin or source server gpg_origin_private_key_passwords: "{{ vaulted_gpg_origin_private_key_passwords }}" # @NOTE list of gpg key passwords from origin or source server
ssh_origin_keypairs_filenames: [] # @NOTE list of basenames (filename sans extension) of SSH keypairs
git_config_name: ~ # @NOTE: has equivalent field under lockdown role vars example YAML file, but different value
git_config_email: ~ # @NOTE: has equivalent field under lockdown role vars example YAML file, but different value

View File

@@ -0,0 +1,128 @@
# 'preferred_signing_key' -> 'gpg_preferred_signing'
# 'gpg_or_ssh_git_signing' -> 'git_signing_key_type'
- name: Install git package
ansible.builtin.package:
name: git
state: latest
- name: Configure git name and email
block:
- name: Configure git name
community.general.git_config:
name: user.name
scope: global
state: present
value: "{{ git_config_name }}"
- name: Configure git email
community.general.git_config:
name: user.email
scope: global
state: present
value: "{{ git_config_email }}"
- name: Configure git signing GPG key
when: git_signing_key_type == "gpg"
block:
- name: Configure specified git signing GPG key
when: preferred_signing_key > -1
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ gpg_origin_private_keyids[preferred_signing_key] }}"
register: selected_signing_key
- name: Configure random git signing GPG key
when: preferred_signing_key <= -1
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ gpg_origin_private_keyids | random }}"
register: selected_signing_key
- name: Configure git signing SSH key
when: git_signing_key_type == "ssh"
block:
- name: Acquire SSH key-pairs from other system
when: not files_mode
block:
- name: Acquire private SSH keys from other system
delegate_to: "{{ ssh_keypairs_origin_host }}"
ansible.builtin.command:
argv:
- cat
- "~/.ssh/{{ item }}.ppk"
loop: "{{ ssh_origin_keypairs_filenames }}"
register: ssh_secrets
- name: Find SSH public keys in other system
delegate_to: "{{ ssh_keypairs_origin_host }}"
ansible.builtin.command:
argv:
- cat
- "~/.ssh/{{ item }}.pub"
loop: "{{ ssh_origin_keypairs_filenames }}"
register: ssh_nonsecrets
- name: Create private SSH keys
ansible.builtin.copy:
content: "{{ item }}"
dest: "{{ ansible_facts['user_dir'] }}/.ssh/{{ ssh_origin_keypairs_filenames[idx] }}.ppk"
force: yes
backup: yes
mode: "0600"
state: present
loop: "{{ ssh_secrets.results }}"
loop_control:
index_var: idx
register: created_ssh_private_keys
- name: Create public SSH keys
ansible.builtin.copy:
content: "{{ item }}"
dest: "{{ ansible_facts['user_dir'] }}/.ssh/{{ ssh_origin_keypairs_filenames[idx] }}.pub"
force: yes
backup: yes
mode: "0644"
state: present
loop: "{{ ssh_nonsecrets.results }}"
loop_control:
index_var: idx
register: created_ssh_public_keys
- name: Acquire SSH key-pairs
when: files_mode
block:
- name: Transfer private SSH keys
ansible.builtin.copy:
src: ssh/{{ ansible_facts['user_id'] }}/{{ item }}.ppk
dest: "{{ ansible_facts['user_dir'] }}/.ssh/{{ item }}.ppk"
force: yes
backup: yes
mode: "0600"
state: present
loop: "{{ ssh_origin_keypairs_filenames }}"
loop_control:
index_var: idx
register: created_ssh_private_keys
- name: Transfer public SSH keys
ansible.builtin.copy:
src: ssh/{{ ansible_facts['user_id'] }}/{{ item }}.pub
dest: "{{ ansible_facts['user_dir'] }}/.ssh/{{ item }}.pub"
force: yes
backup: yes
mode: "0644"
state: present
loop: "{{ ssh_origin_keypairs_filenames }}"
loop_control:
index_var: idx
register: created_ssh_public_keys
- name: Configure acquired, specified SSH public key as git signing key
when: preferred_signing_key > -1
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ created_ssh_public_keys.results[preferred_signing_key] }}"
register: selected_signing_key
- name: Configure acquired, random SSH public key as git signing key
when: preferred_signing_key <= -1
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ created_ssh_public_keys.results | random }}"
register: selected_signing_key

View File

@@ -1,24 +1,39 @@
--- ---
- name: Acquire GPG private keys from other system - name: Acquire GPG private keys from other system
when: not files_mode when: not files_mode
delegate_to: "{{ gpg_private_keys_origin_host }}" block:
ansible.builtin.command: - name: Acquire GPG private keys' contents from other system
argv: delegate_to: "{{ gpg_private_keys_origin_host }}"
- gpg ansible.builtin.command:
- -a argv:
- --export-secret-key - gpg
- "{{ item }}" - -a
loop: "{{ gpg_origin_private_keyids }}" - --export-secret-key
register: gpg_secrets - "{{ item }}"
- name: Create GPG private keys loop: "{{ gpg_origin_private_keyids }}"
register: gpg_secrets
- name: Create GPG private keys using acquired GPG private keys' contents
ansible.builtin.copy:
content: "{{ item }}"
dest: "{{ ansible_facts['user_dir'] }}/.gnupg/{{ gpg_origin_private_keyids[idx] }}.priv.asc"
force: yes
backup: yes
mode: "0600"
state: present
loop: "{{ gpg_secrets.results }}"
loop_control:
index_var: idx
register: created_gpg_private_keys
- name: Acquire GPG private keys
when: files_mode
ansible.builtin.copy: ansible.builtin.copy:
content: "{{ item }}" src: gnupg/{{ ansible_facts['user_id'] }}/{{ item }}.asc
dest: "{{ ansible_facts['user_dir'] }}/.gnupg/{{ ansible_facts['user_id'] }}-{{ idx }}.priv.asc" dest: "{{ ansible_facts['user_dir'] }}/.gnupg/{{ item }}.priv.asc"
force: yes force: yes
backup: yes backup: yes
mode: "0600" mode: "0600"
state: present state: present
loop: "{{ gpg_secrets.results }}" loop: "{{ gpg_origin_private_keyids }}"
loop_control: loop_control:
index_var: idx index_var: idx
register: created_gpg_private_keys register: created_gpg_private_keys

View File

@@ -47,6 +47,7 @@
when: not files_mode and ansible_facts["user_id"] == "root" when: not files_mode and ansible_facts["user_id"] == "root"
block: block:
- name: Acquire list of SSH public keys for sys-admin user - name: Acquire list of SSH public keys for sys-admin user
delegate_to: "{{ ssh_keypairs_origin_host }}"
ansible.builtin.find: ansible.builtin.find:
paths: "{{ lookup('env', 'HOME') }}/.ssh" paths: "{{ lookup('env', 'HOME') }}/.ssh"
patterns: patterns:
@@ -58,10 +59,18 @@
- administrative_user - administrative_user
- admin_ssh - admin_ssh
register: ssh_public_keys register: ssh_public_keys
- name: Acquire contents of SSH public keys for sys-admin user
delegate_to: "{{ ssh_keypairs_origin_host }}"
ansible.builtin.command:
argv:
- cat
- "{{ item.path }}"
loop: "{{ ssh_public_keys.files }}"
register: ssh_public_keys_contents
- name: Register SSH public keys as sys-admin user's authorized keys - name: Register SSH public keys as sys-admin user's authorized keys
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ created_admin.home }}/.ssh/authorized_keys" path: "{{ created_admin.home }}/.ssh/authorized_keys"
line: "{{ lookup('ansible.builtin.file', item.path) }}" line: "{{ item }}"
owner: "{{ created_admin.name }}" owner: "{{ created_admin.name }}"
group: "{{ created_admin.name }}" group: "{{ created_admin.name }}"
mode: "0600" mode: "0600"
@@ -72,8 +81,8 @@
- default - default
- administrative_user - administrative_user
- admin_ssh - admin_ssh
loop: "{{ ssh_public_keys.files }}" loop: "{{ ssh_public_keys_contents.results }}"
- name: Register SSH puplic keys as other users' authorized keys - name: Register SSH public keys as other users' authorized keys
ansible.builtin.copy: ansible.builtin.copy:
src: "ssh/{{ item.name }}/authorized_keys" src: "ssh/{{ item.name }}/authorized_keys"
dest: "{{ item.home }}/.ssh/authorized_keys" dest: "{{ item.home }}/.ssh/authorized_keys"

67
.gitignore vendored
View File

@@ -6,23 +6,58 @@ senpai/
/galaxy_token /galaxy_token
.ansible/log.txt .ansible/log.txt
.ansible/facts/ .ansible/facts/
.ansible/roles/**/vars/*
.ansible/roles/**/files/ssh/*
.ansible/roles/**/*/files/sshd_config.d/*.conf
.ansible/roles/**/*/templates/sshd_config.d/*.conf
.ansible/collections/ansible_collections/ .ansible/collections/ansible_collections/
/playbooks/group_vars/**/main.yml *.bak
/playbooks/host_vars/**/main.yml
/playbooks/**/ssh_keys_vault.yml group_vars/**/main.yml
/playbooks/**/ssh_keys.yml host_vars/**/main.yml
/playbooks/files/**/bash/bash_aliases **/group_vars/**/main.yml
/playbooks/files/**/bash/**/bash_aliases **/host_vars/**/main.yml
/playbooks/files/**/bash/bash_functions group_vars/**/vault.yml
/playbooks/files/**/bash/**/bash_functions host_vars/**/vault.yml
/playbooks/files/**/ssh/config **/group_vars/**/vault.yml
/playbooks/files/**/ssh/**/config **/host_vars/**/vault.yml
/playbooks/files/**/xdg/user-dirs.defaults
/playbooks/files/**/xdg/**/user-dirs.defaults .ansible/roles/**/vars/*
playbooks/vars/ssh_keys_vault.yml
playbooks/vars/ssh_keys.yml
**/playbooks/vars/ssh_keys_vault.yml
**/playbooks/vars/ssh_keys.yml
playbooks/vars/main.yml
playbooks/vars/vault.yml
**/playbooks/vars/main.yml
**/playbooks/vars/vault.yml
files/**/**/config
**/files/**/**/config
files/**/**/authorized_keys
**/files/**/**/authorized_keys
files/**/**/*.conf
**/files/**/**/*.conf
files/**/**/*.dirs
**/files/**/**/*.dirs
files/**/**/*.defaults
**/files/**/**/*.defaults
files/**/**/bash_aliases
**/files/**/**/bash_aliases
files/**/**/bash_functions
**/files/**/**/bash_functions
templates/**/**/config
**/templates/**/**/config
templates/**/**/authorized_keys
**/templates/**/**/authorized_keys
templates/**/**/*.conf
**/templates/**/**/*.conf
templates/**/**/*.dirs
**/templates/**/**/*.dirs
templates/**/**/*.defaults
**/templates/**/**/*.defaults
templates/**/**/bash_aliases
**/templates/**/**/bash_aliases
templates/**/**/bash_functions
**/templates/**/**/bash_functions
hosts.ini hosts.ini
hosts.yml hosts.yml
hosts.yaml hosts.yaml

View File

@@ -1,15 +0,0 @@
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"

View File

@@ -7,39 +7,24 @@
- vars/ssh_keys.yml - vars/ssh_keys.yml
vars: vars:
ansible_user: "{{ passwords[0].username }}" ansible_user: "{{ passwords[0].username }}"
ansible_ssh_user: "{{ passwords[0].username }}"
# @NOTE one of below two lines should be commented/uncommented in a mutually exclusive fashion # @NOTE one of below two lines should be commented/uncommented in a mutually exclusive fashion
# ansible_ssh_private_key_file: "{{ chosen_native_ssh_private_key_file | default(chosen_local_ssh_private_key_file, true) }}" # @NOTE only works with soft-coded SSH key list building # ansible_ssh_private_key_file: "{{ chosen_native_ssh_private_key_file | default(chosen_local_ssh_private_key_file, true) }}" # @NOTE only works with soft-coded SSH key list building
ansible_ssh_private_key_file: "{{ chosen_local_ssh_private_key_file }}" ansible_ssh_private_key_file: "{{ chosen_local_ssh_private_key_file }}" # @NOTE references an inventory / group variable
# @NOTE below three lines should only be uncommented when above two are commented and vice versa; key-based authentication should have already been enabled prior to running this playbook # @NOTE below three lines should only be uncommented when above two are commented and vice versa; key-based authentication should have already been enabled prior to running this playbook
# ansible_password: "{{ passwords[0].password }}" # ansible_password: "{{ passwords[0].password }}"
# ansible_ssh_pass: "{{ passwords[0].username }}"
# ansible_ssh_password: "{{ passwords[0].username }}"
ansible_python_interpreter: “{{ ansible_playbook_python }}” ansible_python_interpreter: “{{ ansible_playbook_python }}”
personal_computers: locals # @NOTE can change to *_households group or {{ name }}_{{ surname }} group name personal_computers: locals # @NOTE can change to *_households group or {{ name }}_{{ surname }} group name
vars_prompt: vars_prompt:
- name: gpg_import_passwords
prompt: Enter space-wrapped colon -separated list of GPG private key passwords
unsafe: yes
private: yes
- name: gpg_or_ssh_git_signing - name: gpg_or_ssh_git_signing
prompt: Enter preferred signing key type (e.g., ssh or gpg) prompt: Enter preferred signing key type (e.g., ssh or gpg)
unsafe: yes unsafe: yes
private: no private: no
default: "ssh" default: "ssh"
- name: gpg_preferred_signing - name: git_preferred_signing
prompt: Enter index or number of preferred signing key (negative number for random) prompt: Enter index or number of preferred signing key (negative number for random)
unsafe: yes unsafe: yes
private: no private: no
default: -1 default: -1
- name: git_config_name
prompt: Enter name for your git configuration
unsafe: yes
private: no
- name: git_config_email
prompt: Enter email for your git configuration
unsafe: yes
private: no
tasks: tasks:
- name: Disable shell access for root - name: Disable shell access for root
ansible.builtin.include_role: ansible.builtin.include_role:
@@ -55,7 +40,7 @@
- name: Create global bash aliases - name: Create global bash aliases
become: yes become: yes
ansible.builtin.copy: ansible.builtin.copy:
src: files/all/bash/bash_aliases src: bash/bash_aliases
dest: /etc/bash_aliases dest: /etc/bash_aliases
owner: root owner: root
group: root group: root
@@ -70,7 +55,7 @@
- name: Create global bash functions - name: Create global bash functions
become: yes become: yes
ansible.builtin.copy: ansible.builtin.copy:
src: files/all/bash/bash_functions src: bash/bash_functions
dest: /etc/bash_functions dest: /etc/bash_functions
owner: root owner: root
group: root group: root
@@ -105,7 +90,7 @@
tags: tags:
- default - default
- source_sys_bashrc - source_sys_bashrc
- name: Start XDG configuration tasks if in servers group - name: Start XDG configuration tasks if current host in servers group
when: "'servers' in group_names and ansible_connection != 'local'" when: "'servers' in group_names and ansible_connection != 'local'"
become: yes become: yes
block: block:
@@ -122,7 +107,7 @@
state: present state: present
- name: Create XDG user home directory environment variables - name: Create XDG user home directory environment variables
ansible.builtin.copy: ansible.builtin.copy:
src: "files/servers/{{ ansible_facts['user_id'] }}/xdg/user-dirs.dirs" src: "xdg/{{ ansible_facts['user_id'] }}/user-dirs.dirs"
dest: "{{ ansible_facts['user_dir'] }}/.config/user-dirs.dirs" dest: "{{ ansible_facts['user_dir'] }}/.config/user-dirs.dirs"
owner: root owner: root
group: root group: root
@@ -135,7 +120,7 @@
- default - default
- create_xdg_config - create_xdg_config
- servers_exclusive - servers_exclusive
- name: Start XDG configuration tasks if current host in specified group - name: Start XDG configuration tasks if current host is local or personal
when: "personal_computers in group_names or ansible_connection == 'local'" when: "personal_computers in group_names or ansible_connection == 'local'"
become: yes become: yes
block: block:
@@ -152,7 +137,7 @@
state: present state: present
- name: Create XDG user home directory environment variables - name: Create XDG user home directory environment variables
ansible.builtin.copy: ansible.builtin.copy:
src: "files/locals/{{ ansible_facts['user_id'] }}/xdg/user-dirs.dirs" src: "xdg/{{ ansible_facts['user_id'] }}/user-dirs.dirs"
dest: "{{ ansible_facts['user_dir'] }}/.config/user-dirs.dirs" dest: "{{ ansible_facts['user_dir'] }}/.config/user-dirs.dirs"
owner: root owner: root
group: root group: root
@@ -165,13 +150,13 @@
- default - default
- create_xdg_config - create_xdg_config
- locals_exclusive - locals_exclusive
- name: Start SSH configuration tasks if current host in specified group - name: Start SSH configuration tasks if current host is local or personal
when: "personal_computers in group_names or ansible_connection == 'local'" when: "personal_computers in group_names or ansible_connection == 'local'"
become: yes become: yes
block: block:
- name: Create user SSH configuration - name: Create user SSH configuration
ansible.builtin.copy: ansible.builtin.copy:
src: "files/locals/ssh/{{ ansible_facts['user_id'] }}/config" src: "ssh/{{ ansible_facts['user_id'] }}/config"
dest: "{{ ansible_facts['user_dir'] }}/.ssh/config" dest: "{{ ansible_facts['user_dir'] }}/.ssh/config"
follow: yes follow: yes
force: yes force: yes
@@ -191,139 +176,22 @@
vars_from: main vars_from: main
handlers_from: main handlers_from: main
tasks_from: gpg tasks_from: gpg
vars:
gpg_keys_origin_host: localhost
gpg_origin_private_key_passwords: "{{ gpg_import_passwords | split(' : ') }}"
tags: tags:
- default - default
- import_gpg_privkeys - import_gpg_privkeys
# @TODO separate below task as lockdown role task, and maybe associated variables to lockdown role defaults/vars dirs - name: Set up git
# @NOTE below depends on variable 'gpg_signing_key' and 'gpg_or_ssh_git_signing' from 'vars_prompt' playbook field ansible.builtin.include_role:
# @NOTE below depends on variable 'gpg_origin_private_keyids' and 'files_mode' found in lockdown role defaults/vars dirs name: lockdown
- name: Install and configure git defaults_from: main
block: vars_from: main
- name: Install git package handlers_from: main
ansible.builtin.package: tasks_from: git
name: git vars:
state: latest git_signing_key_type: gpg_or_ssh_git_signing
- name: Configure git installation preferred_signing_key: git_preferred_signing
block: tags:
- name: Configure git name - default
community.general.git_config: - configure_git
name: user.name
scope: global
state: present
value: "{{ git_config_name }}"
- name: Configure git email
community.general.git_config:
name: user.email
scope: global
state: present
value: "{{ git_config_email }}"
- name: Configure git signing key
block:
- name: Configure git signing GPG key
when: gpg_or_ssh_git_signing == "gpg"
block:
- name: Configure specified git signing GPG key
when: gpg_preferred_signing > -1
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ gpg_origin_private_keyids[gpg_preferred_signing] }}"
- name: Configure random git signing GPG key
when: gpg_preferred_signing <= -1
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ gpg_origin_private_keyids | random }}"
register: randomized_gpg_key_preference
- name: Configure git signing SSH key
when: gpg_or_ssh_git_signing == "ssh"
block:
- name: Acquire SSH key-pairs from other system
when: not files_mode
block:
- name: Acquire private SSH keys from other system
delegate_to: "{{ ssh_keypairs_origin_host }}" # @TODO variable needs declaration/definition
ansible.builtin.command:
argv:
- cat
- ~/.ssh/"{{ item }}.ppk"
loop: "{{ ssh_origin_keypairs_paths }}" # @TODO variable needs declaration/definition--should have max 2 items each without file extension, with private and then public keys having same basename
register: ssh_secrets
- name: Find SSH public keys in other system
delegate_to: "{{ ssh_keypairs_origin_host }}" # @TODO variable needs declaration/definition
ansible.builtin.command:
argv:
- cat
- ~/.ssh/"{{ item }}.pub"
loop: "{{ ssh_origin_keypairs_paths }}" # @TODO variable needs declaration/definition--should have max 2 items each without file extension, with private and then public keys having same basename
register: ssh_nonsecrets
- name: Create private SSH keys
ansible.builtin.copy:
content: "{{ item }}"
dest: "{{ ansible_facts['user_dir'] }}/.ssh/id_ed25519_git.ppk"
force: yes
backup: yes
mode: "0600"
state: present
loop: "{{ ssh_secrets.results }}"
register: created_ssh_private_keys
- name: Create public SSH keys
ansible.builtin.copy:
content: "{{ item }}"
dest: "{{ ansible_facts['user_dir'] }}/.ssh/id_ed25519_git.pub"
force: yes
backup: yes
mode: "0644"
state: present
loop: "{{ ssh_nonsecrets.results }}"
register: created_ssh_public_keys
- name: Acquire SSH key-pairs
when: files_mode
block:
- name: Transfer private SSH keys
ansible.builtin.copy:
src: files/all/ssh/id_ed25519_git.ppk # @TODO change path if and when moved into lockdown role task file and create corresponding file in lockdown role files dir
dest: "{{ ansible_facts['user_dir'] }}/.ssh/id_ed25519_git.ppk"
force: yes
backup: yes
mode: "0600"
state: present
register: created_ssh_private_key
- name: Transfer public SSH keys
ansible.builtin.copy:
src: files/all/ssh/id_ed25519_git.pub # @TODO change path if and when moved into lockdown role task file and create corresponding file in lockdown role files dir
dest: "{{ ansible_facts['user_dir'] }}/.ssh/id_ed25519_git.pub"
force: yes
backup: yes
mode: "0644"
state: present
register: created_ssh_public_key
- name: Configure acquired, specified SSH public key as git signing key
when: ssh_preferred_signing > -1 and not files_mode
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ created_ssh_public_keys.results[ssh_preferred_signing] }}" # @TODO this variable needs declaration/definition
- name: Configure acquired, random SSH public key as git signing key
when: ssh_preferred_signing <= -1 and not files_mode
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ created_ssh_public_keys.results | random }}" # @TODO this variable needs declaration/definition
register: randomized_ssh_pubkey_preference
- name: Configure transferred SSH public key as git signing key
when: ssh_preferred_signing <= -1 and files_mode
community.general.git_config:
name: user.signingkey
scope: global
state: present
value: "{{ created_ssh_public_key.dest }}"

View File

@@ -2,8 +2,18 @@
- name: manage_root - name: manage_root
hosts: servers # @NOTE for IPv6, switch to 'servers6' instead of 'servers4'--for both, 'servers' hosts: servers # @NOTE for IPv6, switch to 'servers6' instead of 'servers4'--for both, 'servers'
remote_user: root # MUST be run as root remote_user: root # MUST be run as root
# roles: vars:
# - lockdown ansible_user: root
# ansible_ssh_user: root
vars_prompt:
- name: ansible_password
prompt: Enter pasword for root user of VPS
unsafe: yes
private: yes
# - name: ansible_ssh_pass
# prompt: Enter pasword for root user of VPS
# unsafe: yes
# private: yes
tasks: tasks:
- name: Set up sys-admin account on VPS and secure VPS - name: Set up sys-admin account on VPS and secure VPS
ansible.builtin.include_role: ansible.builtin.include_role:

View File

@@ -1,5 +1,5 @@
--- ---
- name: Lock down VPS - name: Lock down VPS
ansible.builtin.import_playbook: manage_root.yml ansible.builtin.import_playbook: manage_root.yml
- name: Disable shell for root - name: Bootstrap VPS
ansible.builtin.import_playbook: init_login.yml ansible.builtin.import_playbook: init_login.yml