Initial commit

This commit is contained in:
Jan Beilicke 2020-03-24 00:55:53 +01:00
commit 549ca9b641
12 changed files with 222 additions and 0 deletions

39
README.md Normal file
View file

@ -0,0 +1,39 @@
Common tasks
============
Provides common tasks like creating required users, configuring locales or even bootstrapping python.
Requirements
------------
Role Variables
--------------
Defaults:
```
locales_gen:
- en_US.UTF-8
- de_DE.UTF-8
locales_default: de_DE.UTF-8
users:
- vagrant
sudoers:
- vagrant
```
Dependencies
------------
Example Playbook
----------------
License
-------
MIT
Author Information
------------------
This role was created in 2020 by [Jan Beilicke](https://jotbe.io).

10
defaults/main.yml Normal file
View file

@ -0,0 +1,10 @@
---
# defaults file for common
locales_gen:
- en_US.UTF-8
- de_DE.UTF-8
locales_default: de_DE.UTF-8
users:
- vagrant
sudoers:
- vagrant

2
handlers/main.yml Normal file
View file

@ -0,0 +1,2 @@
---
# handlers file for common

53
meta/main.yml Normal file
View file

@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your 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.4
# 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.

4
tasks/ansible-debian.yml Normal file
View file

@ -0,0 +1,4 @@
---
- name: Install Ansible
raw: test -e /usr/local/bin/ansible || pip3 install ansible
changed_when: false

22
tasks/locales-debian.yml Normal file
View file

@ -0,0 +1,22 @@
---
- name: Generate locals
locale_gen:
name: "{{ item }}"
state: present
loop: "{{ locales_gen }}"
- name: Get current locale
command: localectl status
register: locale_status
changed_when: false
- name: Extract LANG from current locale configuration
set_fact:
locale_lang: "{{ locale_status.stdout | regex_search('LANG=([^\n]+)', '\\1') | first }}"
- debug:
msg: "{{ locale_lang }}"
- name: Set default locale
command: localectl set-locale LANG={{ locales_default }}
when: locale_lang != locales_default

26
tasks/main.yml Normal file
View file

@ -0,0 +1,26 @@
---
# tasks file for common
- include: locales-debian.yml
become: true
when: ansible_facts['os_family'] == 'Debian'
- include: users.yml
become: true
- include: python-debian.yml
become: true
when: ansible_facts['os_family'] == 'Debian'
- include: ansible-debian.yml
become: true
- name: Install basic packages
apt:
name: "{{ packages }}"
state: present
#update_cache: yes
vars:
packages:
- htop
- tmux
become: yes
- name: Copy tmux config
copy: src=files/tmux.conf dest=/home/{{ ansible_user }}/.tmux.conf mode=0644

8
tasks/python-debian.yml Normal file
View file

@ -0,0 +1,8 @@
---
- name: Install Python3
raw: test -e /usr/bin/python3 || (apt update && apt install -y --force-yes python3)
changed_when: false
- name: Install pip3
raw: test -e /usr/bin/pip3 || (apt update && apt install -y --force-yes python3-pip)
changed_when: false

49
tasks/users.yml Normal file
View file

@ -0,0 +1,49 @@
---
- name: 'Install required packages'
pkgng: name={{item}} state=present
with_items:
- sudo
when: ansible_facts['os_family'] == 'FreeBSD'
- name: 'Allow wheel group to do passwordless sudo'
lineinfile:
dest: /usr/local/etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD:ALL'
validate: visudo -cf %s
when: ansible_facts['os_family'] == 'FreeBSD'
- name: 'Allow wheel group to do passwordless sudo'
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD:ALL'
validate: visudo -cf %s
when: ansible_facts['os_family'] == 'Debian'
- name: 'Create users with corresponding groups'
user:
name: "{{ item }}"
groups: users
with_items: "{{ users }}"
- name: 'Add corresponding authorized_keys to each user'
authorized_key:
user: "{{ item }}"
state: present
key: "{{ lookup('file', 'public_keys/id_{{ item }}.pub') }}"
with_items: "{{ users }}"
- name: 'Ensure that wheel group is existing'
group:
name: wheel
state: present
- name: 'Add sudoers user to wheel group'
user:
name: "{{ item }}"
groups: wheel
append: yes
with_items: "{{ sudoers }}"

2
tests/inventory Normal file
View file

@ -0,0 +1,2 @@
localhost

5
tests/test.yml Normal file
View file

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- common

2
vars/main.yml Normal file
View file

@ -0,0 +1,2 @@
---
# vars file for common