Skip to content

Commit

Permalink
Merge branch 'role_rework' into 'master'
Browse files Browse the repository at this point in the history
Reworking role to simplify and bring up to current standards

See merge request ansible.ext/roles/usersandgroups!2
  • Loading branch information
Tristan Findley committed Oct 25, 2024
2 parents 37ccf00 + 4934148 commit 4f17195
Show file tree
Hide file tree
Showing 23 changed files with 145 additions and 415 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sudo: false
addons:
apt:
packages:
- python-pip
- python-pip

install:
# Install ansible
Expand All @@ -26,4 +26,4 @@ script:
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
webhooks: https://galaxy.ansible.com/api/v1/notifications/
92 changes: 52 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,73 @@
Role Name
=========
# Users and Groups

A brief description of the role goes here.

Requirements
------------
## 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
--------------
## 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
------------
## 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.

Generate password
-----------------
python3 -c 'import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass("Confirm: ")) else exit())'

Example Playbook
----------------
## 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
become: yes
gather_facts: true
roles:
- role: '/home/tristan/ansible/roles_vss/users'
vars:

groups_present:
- "ansible"

groups_absent:
- "group_to_delete

users_present:
- {username: user1, sudo: True, enabled: True, fname: User, sname: One, groups: "ansible", email: [email protected], password: EncryptedPasswordUser1, rsa: "https://github.com/user1.keys" }
- {username: user2, sudo: True, enabled: True, fname: User, sname: Two, groups: "ansible", email: [email protected], password: EncryptedPasswordUser2, rsa: "ssh-rsa enteryourrpublickeystringhere [email protected]" }
- {username: user3, sudo: True, enabled: False, fname: User, sname: Three, groups: "ansible", email: [email protected], password: EncryptedPasswordUser3, rsa: }
- {username: user4, sudo: False, enabled: True, fname: User, sname: Four, groups: "ansible", email: [email protected], password: EncryptedPasswordUser4, rsa: "user2_id_rsa.pub"}

users_absent:
- "user5"
- "user6"

License
-------
```yml
- hosts: servers
become: yes
gather_facts: true
roles:
- role: 'usersandgroups'
vars:

# Adding a user
- username: "username"
state: present
fname: "user"
sname: "name"
email: [email protected]
password: 'set using openssl passwd -6'
sudo: true
groups:
- "grouphere"
sshkeys:
- 'copypaste ssh key'
- 'or use file read'

# Removing a user
- username: "another.user"
state: absent

# Managing Groups
usersandgroups_groups:
- name: "dcinfra"
state: present
```
### Generate password
Preferred method:
```bash
set using openssl passwd -6
```

Alternative method:
```bash
python3 -c 'import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass("Confirm: ")) else exit())'
```


## License

BSD

Author Information
------------------
## Author Information

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
26 changes: 25 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
---
# defaults file for users
# defaults file for users

usersandgroups_users:
# Adding a user
- username: "username"
state: present
fname: "user"
sname: "name"
email: [email protected]
password: 'set using openssl passwd -6'
sudo: true
groups:
- "grouphere"
sshkeys:
- 'copypaste ssh key'
- 'or use file read'

# Removing a user
- username: "another.user"
state: absent

# Managing Groups
usersandgroups_groups:
- name: "dcinfra"
state: present
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
# handlers file for users
# handlers file for users
33 changes: 13 additions & 20 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
galaxy_info:
role_name: usersandgroups
namespace: tfindley
author: Tristan Findley
description: Manage users and groups
company: TFindley (tfindley.co.uk)
Expand All @@ -14,9 +16,9 @@ galaxy_info:
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: MIT
license: BSD

min_ansible_version: 2.9
min_ansible_version: '2.9'

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
Expand All @@ -28,24 +30,15 @@ galaxy_info:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: RedHat
versions:
- 7
- 8
- name: CentOS
versions:
- 7
- 8
- name: Debian
versions:
- buster
- stretch
- name: Ubuntu
versions:
- 18.04
- 18.10
- 19.04
- 19.10
- name: EL
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
Expand Down
22 changes: 0 additions & 22 deletions molecule/default/INSTALL.rst

This file was deleted.

22 changes: 0 additions & 22 deletions molecule/default/converge.yml

This file was deleted.

25 changes: 0 additions & 25 deletions molecule/default/molecule.yml

This file was deleted.

9 changes: 0 additions & 9 deletions molecule/default/verify.yml

This file was deleted.

Loading

0 comments on commit 4f17195

Please sign in to comment.