init
This commit is contained in:
38
roles/common/README.md
Executable file
38
roles/common/README.md
Executable 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).
|
||||
3
roles/common/defaults/main.yml
Executable file
3
roles/common/defaults/main.yml
Executable file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
# leer
|
||||
...
|
||||
1
roles/common/files/ansible_rsa.pub
Executable file
1
roles/common/files/ansible_rsa.pub
Executable file
@@ -0,0 +1 @@
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC0dCYmmRwBGoH1bB3VvYqZOb24EKmSJaNAnDgUusbTCgXlhf1LPDirJS2rJrWaEs4alybChpFPKscvHf6ka2nFN1avWGcXitnSiPzIiBZqmOyL34aqwEIxnDNesw3M18WsySMQDQ8HR+PboQ9SQnxEW2oHukDoxEyeE6xts5mKv5ri69bTBVmvD1F8VNATDR9irjht2zDN0MMp2A6zPwCT5qH+H8Xl6p7nPxq8hsKrTuV5PaAQ0SZWFIczzlgqiDA595KoSFuOV5c0s8nAKjz55YJneo8hfxZ6AEx1/QQPWkTuYiW8xB1O6m6RRq+lMtT6NocI+S9pQWwZNU2ipvxa+EsC5MjMR/NFmef65Ak1ic4GjQwkNmDCxmEeFAtH/oLFtANsEK05y0jx/KKeLB07tQWboqTR9wJz/QmZv3yLZThg2eCi8MO1zxXDmqIAT0XPSwiivyWcki4To9G6EOPcXOLXd4Ap5LcC7qWJHiQ70ddgj+pNv5aLfzuZdh7+5jM= ansible@LB-DSFS026406
|
||||
1
roles/common/files/martin_rsa.pub
Executable file
1
roles/common/files/martin_rsa.pub
Executable file
@@ -0,0 +1 @@
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDE16YLmHW4TkwvGdXP8kHtQYzLSa9A9FxccOe6tCUF+Qyb34Jkk7Rw/oJvMrTPMyBUkeQDIML/UuGFCzb6Zh6NA76zbd1uKlenAgEyzck+MNHgzExECIJoWpqEZf1xYaJoigQ38ct/sepvdHuADFMSfiS/syES2bUT/H7JF5rDMrGEmzZjeisPcLx8+e8BK5wY8st9HaBbTR/ngqpqKQwVjKoZgIH8ozVWg6OnIdRjbDD//teYcRe+VlZ2MMr4hfb80EJw3PjZMjA3PUb6cwWqpgpzAtMB6jKf5H1fzgEwGOFHwuv3Zs6mDwD0qK2xPTrsXYQmqqnKyeOdxb4VPRBGcO1WgoliqYgZCy74WzKr4L/y7Z+6xsdOB60WVQrtCflxnz9wdh/pgNlEVULMRKXe3TKxtVdxcCECSe5e3YVaZ4BMvAHwkUCbVWb4Ny2GmPKjUHAkA3dzdmUhtAR7IT1VFiS1s1Lzf/xf6asazw4qYM7CfJOn8yu7bxmYjEnywzUrg7jga5/5xLS74QnNeTuVoMdVjK1y42LAOrrRyXCO0w8WtMyPTZvTUWkHNQ9Jqdiw6/K9Ai+9iTl2P55pAWogDGLvywk7PGH6+vNyGii6xEHPbR1/tgMVgrMDnbgtrDH2kMPcCinH5M6eb1lGG45KBOGY7zEFBQDDtwGkkMQUFQ== martin@martin-NUC10
|
||||
2
roles/common/handlers/main.yml
Executable file
2
roles/common/handlers/main.yml
Executable file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
# handlers file for common
|
||||
52
roles/common/meta/main.yml
Executable file
52
roles/common/meta/main.yml
Executable file
@@ -0,0 +1,52 @@
|
||||
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:
|
||||
|
||||
#
|
||||
# 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.
|
||||
46
roles/common/tasks/docker.yml
Executable file
46
roles/common/tasks/docker.yml
Executable file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: Install docker prerequisites
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop:
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gnupg
|
||||
- lsb-release
|
||||
|
||||
- name: One way to avoid apt_key once it is removed from your distro
|
||||
block:
|
||||
- name: create keyring folder
|
||||
file:
|
||||
path: /etc/apt/keyrings
|
||||
mode: '0755'
|
||||
recurse: true
|
||||
|
||||
- name: Check if docker key already exists
|
||||
stat:
|
||||
path: /etc/apt/keyrings/docker.gpg
|
||||
register: docker_gpg
|
||||
|
||||
- name: docker repo key
|
||||
shell:
|
||||
cmd: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
when: docker_gpg.stat.exists == false
|
||||
|
||||
- name: add docker repo | apt source
|
||||
ansible.builtin.apt_repository:
|
||||
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
|
||||
state: present
|
||||
|
||||
- name: Install docker
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
loop:
|
||||
- docker-ce
|
||||
- docker-ce-cli
|
||||
- containerd.io
|
||||
- docker-buildx-plugin
|
||||
- docker-compose-plugin
|
||||
...
|
||||
79
roles/common/tasks/main.yml
Executable file
79
roles/common/tasks/main.yml
Executable file
@@ -0,0 +1,79 @@
|
||||
---
|
||||
- name: Include docker tasks
|
||||
include_tasks:
|
||||
file: docker.yml
|
||||
|
||||
- name: Create default groups
|
||||
group:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop:
|
||||
- docker
|
||||
- ansible
|
||||
|
||||
- name: Create default user
|
||||
user:
|
||||
name: "martin"
|
||||
uid: "1000"
|
||||
groups: docker,ansible
|
||||
append: yes
|
||||
shell: /bin/bash
|
||||
state: present
|
||||
|
||||
- name: Create appusers
|
||||
user:
|
||||
name: "{{ item }}"
|
||||
shell: /bin/bash
|
||||
state: present
|
||||
loop:
|
||||
- "{{ appusers }}"
|
||||
|
||||
- name: create root authorized_keys
|
||||
template:
|
||||
src: root_authorized_keys.j2
|
||||
dest: /root/.ssh/authorized_keys
|
||||
owner: root
|
||||
mode: '0600'
|
||||
|
||||
#- name: Create user authorized_keys
|
||||
# authorized_key:
|
||||
# user: "{{ item }}"
|
||||
# key: "{{ item }}_rsa.pub"
|
||||
# loop:
|
||||
# - '{{ keys }}'
|
||||
|
||||
- name: apt update && apt upgrade
|
||||
apt:
|
||||
name: "*"
|
||||
state: latest
|
||||
update_cache: true
|
||||
|
||||
- name: Install default packages
|
||||
apt:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop:
|
||||
- "{{ default_pkgs }}"
|
||||
|
||||
- name: create docker/watchtower folder
|
||||
file:
|
||||
path: /opt/docker/watchtower
|
||||
owner: 1000
|
||||
group: 1000
|
||||
mode: '0755'
|
||||
state: directory
|
||||
|
||||
- name: Place watchtower docker-compose.yaml
|
||||
template:
|
||||
src: docker-compose.yaml.j2
|
||||
dest: /opt/docker/watchtower/docker-compose.yaml
|
||||
notify: restart docker-compose
|
||||
tags: setup,update
|
||||
|
||||
- name: Start watchtower
|
||||
community.docker.docker_compose:
|
||||
project_src: /opt/docker/watchtower
|
||||
state: present
|
||||
pull: true
|
||||
tags: test
|
||||
...
|
||||
17
roles/common/templates/docker-compose.yaml.j2
Executable file
17
roles/common/templates/docker-compose.yaml.j2
Executable file
@@ -0,0 +1,17 @@
|
||||
# ansible managed #
|
||||
|
||||
version: '3.3'
|
||||
services:
|
||||
watchtower:
|
||||
image: containrrr/watchtower
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
environment:
|
||||
- WATCHTOWER_SCHEDULE=0 0 4 * * *
|
||||
- WATCHTOWER_CLEANUP=true
|
||||
- WATCHTOWER_TIMEOUT=30s
|
||||
- WATCHTOWER_INCLUDE_RESTARTING=true
|
||||
- WATCHTOWER_ROLLING_RESTART=true
|
||||
- TZ="Europe/Berlin"
|
||||
restart: unless-stopped
|
||||
5
roles/common/templates/root_authorized_keys.j2
Executable file
5
roles/common/templates/root_authorized_keys.j2
Executable file
@@ -0,0 +1,5 @@
|
||||
{% for user in keys %}
|
||||
{% if keys[user].ssh_as_root | default(false) %}
|
||||
{{ keys[user].pub_key }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
3
roles/common/templates/user_authorized_keys.j2
Executable file
3
roles/common/templates/user_authorized_keys.j2
Executable file
@@ -0,0 +1,3 @@
|
||||
{% for user in users %}
|
||||
{{ keys[user].pub_key }}
|
||||
{% endfor %}
|
||||
2
roles/common/tests/inventory
Executable file
2
roles/common/tests/inventory
Executable file
@@ -0,0 +1,2 @@
|
||||
localhost
|
||||
|
||||
5
roles/common/tests/test.yml
Executable file
5
roles/common/tests/test.yml
Executable file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- common
|
||||
23
roles/common/vars/main.yml
Executable file
23
roles/common/vars/main.yml
Executable file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
appusers:
|
||||
- ansible
|
||||
|
||||
keys:
|
||||
martin:
|
||||
ssh_as_root: true
|
||||
pub_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDE16YLmHW4TkwvGdXP8kHtQYzLSa9A9FxccOe6tCUF+Qyb34Jkk7Rw/oJvMrTPMyBUkeQDIML/UuGFCzb6Zh6NA76zbd1uKlenAgEyzck+MNHgzExECIJoWpqEZf1xYaJoigQ38ct/sepvdHuADFMSfiS/syES2bUT/H7JF5rDMrGEmzZjeisPcLx8+e8BK5wY8st9HaBbTR/ngqp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DSFS026406"
|
||||
|
||||
default_pkgs:
|
||||
- curl
|
||||
- git
|
||||
- net-tools
|
||||
- nfs-common
|
||||
- nmap
|
||||
- screen
|
||||
- tar
|
||||
- zip
|
||||
- unzip
|
||||
|
||||
...
|
||||
Reference in New Issue
Block a user