first commit

This commit is contained in:
ansible user
2025-07-21 10:47:59 +02:00
commit f7e76e9748
71 changed files with 1727 additions and 0 deletions

6
serv-04-adduser/README Normal file
View File

@@ -0,0 +1,6 @@
1. WE DO NOT create users w/o their SSH key
2. This is to create user:
~/ansible-venv/bin/ansible-playbook -i hosts serv-04-adduser.yml -eusername=pavel -euserkey=pavel.pub -euseraction=add --limit=sterver01 -K
3. This is to remove user
~/ansible-venv/bin/ansible-playbook -i hosts serv-04-adduser.yml -eusername=pavel -euseraction=remove --limit=sterver01 -K

38
serv-04-adduser/README.md Normal file
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).

View File

@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
---
# defaults file for serv-04-adduser

View File

@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCF3hyP//3VBrF+tr/uF3pTzIvUd8YkPkdnBk9+0kmbKqeYgApMUCqaOezrQHIczBSgrLk8ygY5mjD7Sxs9JpMuxqtnWLK5rZukd5+m4lVe0HmmtaLZLrEYhO9w0WKVl660m3tCuma8pVTLD/WQiiqUQ6HhccWs8L3IhG7tujbMhdc3PYmXPGUGvVny5DFLW7N99nYYO4K43YXHp+u6ofPuxuqjZkpYaDilIKXsXUdq8HOSNz1qVWnYZCfOYqmc2l5AKhACqAbvMexnGMVek1cXw4uA+IHu/fVnjmPTUJrPQf0n29LMMygoZg74Dqnnd8jhdk24vavwF4lumszJ9kGayWEKk0Jf3q5ceet8Q6QgYKU8nXuiGWtDg/WtU2PMJT5Cd4BXbfaKdH1ZKelZbKw6p4Il+XB5pHHwQ8LDbHIAQCbj3514VpvibkhEERYym6nr1Jr9lLMieqOupGPDCIHOW1XwkXNDvxuB4ZOJ5wNrBUka1jexEGHtwbIisvehYTnrnRS5Nkv2gHcDleN0zAyd09w752y1kk7V5M4NLh4PTORO/yKmE+ZdeEiyIu1pirjSab4HbvhF3gnSXqWzq4pTG3JofPgFfMveKyUEwtnTiSPtEpjz6q6Haxg3Lgt2ciO1cX58M5EkAUxU2+qqBvDk/1TsvwZDo65gDRJxISuHCw== ansible@labjump

View File

@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC+5WJErVzuukfXzOL/KCi27oQ+RL2wLCZEi+i3OLSou cnms@8devices.com

View File

@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINRnOcWyYgWQZcZBPvVNzkcfsta+k5kSLRebVL/F86+k marc@ikeja.co.za

View File

@@ -0,0 +1,2 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7ut7tytWiBJp8pzYxuDmfiz6pnm+UuYG9xYUFjqAcbYdCvRJHRDwZjj+CIKgjGmh4Lu6OouNgXxWsj/3vtJJvR97hdropEbg9eYyu3YKIn7VJGK/c1Kasoqy0mhRjhoVdQVlE4KEL3h6dXN+dmDD9fvPIARguuJwlayktl1OcfLE0BGMHBwLg9wDzTt2ngWXWdGo+LsH683zKI0m7/N92W+Ryx7d58KC4F9ce4p8mYDtiwhig0fNXenLLVkG033WqfsfpZQVe+hW8C5yketWRZlXCT9KFs0x3Q9J7+itvzRqlDvZy/UNtSj5BAKDIeM9cW/JSRJ3CQD55SjqERd4Z admin

View File

@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAuOyqS81+IuvvkCn/yfFr6NXxrBxHxkeQ7S3x6SRh81 mindaugas@8devices.com

View File

@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOyPSe6XOJxzdsr77HU6nZgyGOdI3w16kaxs1Ozq6beY pavel

View File

@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
---
# handlers file for serv-04-adduser

View File

@@ -0,0 +1,35 @@
#SPDX-License-Identifier: MIT-0
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# 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: license (GPL-2.0-or-later, MIT, etc)
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.

View File

@@ -0,0 +1,90 @@
---
- name: Ensure user exists
ansible.builtin.user:
name: "{{ username }}"
password: "{{ userpass | password_hash('sha512') }}"
shell: /bin/bash
state: present
create_home: yes
when: useraction == "add"
- name: Create .ssh directory
ansible.builtin.file:
path: "/home/{{ username }}/.ssh"
state: directory
owner: "{{ username }}"
group: "{{ username }}"
mode: '0700'
when: useraction == "add"
- name: Upload authorized SSH key
ansible.builtin.copy:
src: "files/sshkeys/{{ userkey }}"
dest: "/home/{{ username }}/.ssh/authorized_keys"
owner: "{{ username }}"
group: "{{ username }}"
mode: '0600'
when: useraction == "add"
# REMOVE USER
#- name: Remove user and home directory
# ansible.builtin.user:
# name: "{{ username }}"
# state: absent
# remove: yes
# when: useraction == "remove"
- name: Allow {{ username }} to switch to 'docker' user without password
ansible.builtin.copy:
dest: "/etc/sudoers.d/{{ username }}-su-docker"
content: "{{ username }} ALL=(ALL) NOPASSWD: /bin/su - docker"
owner: root
group: root
mode: '0440'
when: useraction == "add"
- name: Find processes owned by the user (initial)
ansible.builtin.shell: "ps -u {{ username }} -o pid,comm,args --no-headers || true"
register: user_process_list
changed_when: false
when: useraction == "remove"
- name: Display processes owned by user before killing
ansible.builtin.debug:
msg: "{{ item }}"
loop: "{{ user_process_list.stdout_lines }}"
when: useraction == "remove"
- name: Extract PIDs of user processes
ansible.builtin.shell: "pgrep -u {{ username }} || true"
register: user_pids
changed_when: false
when: useraction == "remove"
- name: Kill user processes (if any)
ansible.builtin.shell: "kill -9 {{ user_pids.stdout_lines | join(' ') }}"
when:
- useraction == "remove"
- user_pids.stdout != ""
- name: Remove user and home directory
ansible.builtin.user:
name: "{{ username }}"
state: absent
remove: yes
when: useraction == "remove"
- name: List remaining processes for the user (after kill)
ansible.builtin.shell: "ps -u {{ username }} -o pid,comm,args --no-headers || true"
register: remaining_procs
changed_when: false
when: useraction == "remove"
- name: Display remaining processes (manual check)
ansible.builtin.debug:
msg: |
Remaining processes for '{{ username }}' after kill:
{{ remaining_procs.stdout | default('None') }}
when: useraction == "remove"

View File

@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
localhost

View File

@@ -0,0 +1,6 @@
#SPDX-License-Identifier: MIT-0
---
- hosts: localhost
remote_user: root
roles:
- serv-04-adduser

View File

@@ -0,0 +1,3 @@
#SPDX-License-Identifier: MIT-0
---
# vars file for serv-04-adduser