add urubamba playbooks

This commit is contained in:
Vaclav Uruba 2023-07-21 13:50:26 +02:00
parent 99708799ff
commit 8d8f209d2f
Signed by: uruba
GPG Key ID: 9D8E987C4B2E1E9C
8 changed files with 108 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
**/files/*.key.pub

View File

@ -0,0 +1,4 @@
- name: Server setup
hosts: all
roles:
- users

View File

@ -0,0 +1,14 @@
- name: Server update
hosts: all
tasks:
- name: Update all packages
ansible.builtin.apt:
name: "*"
state: latest # noqa package-latest
register: result_update
- name: Print update result
ansible.builtin.debug:
msg: "{{ result_update.stdout_lines }}"
- name: Remove dependencies that are no longer required
ansible.builtin.apt:
autoremove: true

View File

@ -0,0 +1,2 @@
---
sshd_config_path: /etc/ssh/sshd_config

View File

View File

@ -0,0 +1,5 @@
---
- name: "Restart ssh daemon"
ansible.builtin.service:
name: sshd
state: restarted

View File

@ -0,0 +1,51 @@
galaxy_info:
author: Václav Uruba
description: create users
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: MIT
min_ansible_version: "2.1"
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@ -0,0 +1,31 @@
---
- name: "Create admin user accounts"
ansible.builtin.user:
name: "{{ item.username }}"
password: "{{ item.password | password_hash('sha512') }}"
shell: /bin/bash
with_items: "{{ admin_users }}"
- name: "Add authorized keys for admin user accounts"
ansible.posix.authorized_key:
user: "{{ item.username }}"
key: "{{ lookup('file', 'files/' + item.username + '.key.pub') }}"
with_items: "{{ admin_users }}"
register: add_authorized_keys
- name: "Add admin user accounts to sudoers file"
community.general.sudoers:
name: "sudo-{{ item.username }}"
user: "{{ item.username }}"
nopassword: false
commands: ALL
with_items: "{{ admin_users }}"
- name: "Disable password login"
ansible.builtin.lineinfile:
dest: "{{ sshd_config_path }}"
regexp: '^(#\s*)?PasswordAuthentication '
line: 'PasswordAuthentication no'
when:
- add_authorized_keys is succeeded
notify: restart sshd