Initial ansible onboard

This commit is contained in:
2024-09-24 15:19:51 +02:00
parent 7366659355
commit f445996797
492 changed files with 2214589 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
---
exclude_paths:
- .git/
- .github/
- tests/
enable_list:
- fqcn-builtins # opt-in
warn_list:
- line-length
- yaml[line-length]
+15
View File
@@ -0,0 +1,15 @@
---
extends: default
ignore: ".tox*\n.git*"
rules:
line-length:
max: 120
level: warning
comments:
min-spaces-from-content: 1
comments-indentation: false
braces:
max-spaces-inside: 1
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
+38
View File
@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
@@ -0,0 +1,3 @@
---
# defaults file for manage_users
ssh_users: []
@@ -0,0 +1,2 @@
---
# handlers file for manage_users
+39
View File
@@ -0,0 +1,39 @@
---
galaxy_info:
author: Alexandre Pires
description: Manage users on Linux
company: A13Labs
role_name: manage_users
namespace: a13labs
# 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:
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.
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
gather_facts: true
tasks:
- name: Include role manage_users
ansible.builtin.include_role:
name: manage_users
@@ -0,0 +1,29 @@
---
driver:
name: podman
platforms:
- name: instance
image: ubuntu:20.04
pre_build_image: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
provisioner:
name: ansible
env:
USER_PASSWORD_TESTUSER: "123abcdef"
USER_PASSWORD_SALT: "12345678"
inventory:
host_vars:
instance:
ssh_users:
- username: testuser
comment: Test User
enabled: true
sudoer: true
pubkey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDZ6
playbooks:
converge: converge.yml
prepare: prepare.yml
verifier:
name: ansible
@@ -0,0 +1,10 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Update cache # noqa no-changed-when
ansible.builtin.raw: apt update
- name: Install required packages # noqa no-changed-when
ansible.builtin.raw: apt install -y python3 sudo
@@ -0,0 +1,9 @@
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
ansible.builtin.assert:
that: true
+35
View File
@@ -0,0 +1,35 @@
---
- name: Read salt from environment
ansible.builtin.set_fact:
user_password_salt: "{{ lookup('env', 'USER_PASSWORD_SALT') | default('') }}"
- name: Adding ssh users
become: true
ansible.builtin.user:
name: "{{ item.username }}"
comment: "{{ item.comment }} ( Managed by ansible )"
password: "{{ lookup('env', 'USER_PASSWORD_' + (item.username | upper)) | password_hash('sha512', user_password_salt) }}"
state: "{{ 'absent' if item.enabled is defined and not item.enabled else 'present' }}"
shell: "{{ item.shell if item.shell is defined else '/bin/bash' }}"
loop: "{{ ssh_users }}"
- name: "Add SSH Authorized key"
become: true
ansible.posix.authorized_key:
user: "{{ item.username }}"
key: "{{ item.pubkey }}"
state: "{{ 'present' if item.pubkey is defined else 'absent' }}"
when: item.pubkey is defined
loop: "{{ ssh_users }}"
- name: Create sudoers.d entry if user allowed
become: true
ansible.builtin.copy:
dest: "/etc/sudoers.d/{{ item.username }}"
content: |
{{ item.username }} ALL=(ALL) ALL
owner: root
group: root
mode: "0600"
when: item.sudoer is defined and item.sudoer
loop: "{{ ssh_users }}"
@@ -0,0 +1,2 @@
localhost
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- manage_users
+2
View File
@@ -0,0 +1,2 @@
---
# vars file for manage_users