Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaffen authored Jan 5, 2024
0 parents commit e8acdd3
Show file tree
Hide file tree
Showing 44 changed files with 411 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
skip_list:
- yaml[comments-indentation]

extra_vars:
hostvars:
localhost:
example_host_var: dummy_host
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*.{yml,yaml}]
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
trim_final_newlines = true
insert_final_newline = true
max_line_length = 160
41 changes: 41 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
on: # yamllint disable-line rule:truthy
push:
branches:
- main
pull_request:

name: ⚒️ CI

jobs:
yamllint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: yamllint
uses: ibiqlik/action-yamllint@v3
with:
file_or_dir: .
config_file: .yamllint

ansible-lint:
runs-on: ubuntu-latest
container: pipelinecomponents/ansible-lint:latest
steps:
- uses: actions/checkout@v4
- run: |
git --version
ansible-lint --version
ansible-lint -v
ansible-syntax:
runs-on: ubuntu-latest
container: cytopia/ansible:latest
steps:
- uses: actions/checkout@v4
- run: |
apk add git
git --version
ansible-galaxy --version
ansible-playbook --version
ansible-playbook --syntax-check --list-tasks playbooks/*.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
37 changes: 37 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
stages:
- lint

yamllint:
stage: lint
image:
name: cytopia/yamllint:latest
entrypoint: ["/bin/ash", "-c"]
script:
- yamllint --version
- yamllint .

ansible-lint:
stage: lint
image: pipelinecomponents/ansible-lint:latest
script:
- git --version
- ansible-lint --version
- ansible-lint
- ansible-lint roles/

ansible-syntax:
stage: lint
image:
name: cytopia/ansible:latest
entrypoint: ["/bin/sh", "-c"]
variables:
ANSIBLE_ROLES_PATH: roles
script:
- apk add git
- git --version
- ansible-galaxy --version
- ansible-playbook --version
- ansible-galaxy role install -r roles/requirements.yml
- ansible-galaxy collection install -r collections/requirements.yml
- ansible-playbook --syntax-check --list-tasks playbooks/*.yml
16 changes: 16 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
extends: default

rules:
line-length:
max: 160
empty-lines:
max: 1
max-start: 0
max-end: 1
hyphens:
max-spaces-after: 1
indentation:
spaces: 2
indent-sequences: whatever
check-multi-line-strings: false
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Ansible Control Repository Template
[![⚒️ CI](https://github.com/betadots/ansible-control-repo-template/actions/workflows/ci.yaml/badge.svg)](https://github.com/betadots/ansible-control-repo-template/actions/workflows/ci.yaml)
[![Created by betadots GmbH](https://img.shields.io/badge/Created_by-betadots_GmbH-blue)](https://www.betadots.de)

# Usage

Copy this repository into your own Git Server.
Then clone it from there and adapt your changes.

# What's in this template

Here is a visual representation of the structure of this repository:

```bash
bin/helpers # here you may place scripts which help the ci or the ansible surroundings
inventories/ #
production/ #
hosts # inventory file for production servers
group_vars/ # here we assign variables to particular groups
host_vars/ # here we assign variables to particular systems
staging/ #
hosts # inventory file for staging environment
group_vars/ # here we assign variables to particular groups
host_vars/ # here we assign variables to particular systems
#
library/ # if any custom modules, put them here (optional)
module_utils/ # if any custom module_utils to support modules, put them here (optional)
filter_plugins/ # if any custom filter plugins, put them here (optional)
#
site.yml # master playbook
#
playbooks/ # put all playbooks here
foo.yml # foo demo playbook
#
collections/ # local collections
requirements.yml # <-- required remote collections

roles/ #
common/ # this hierarchy represents a "role"
tasks/ #
main.yml # <-- tasks file can include smaller files if warranted
handlers/ #
main.yml # <-- handlers file
templates/ # <-- files for use with the template resource
files/ # <-- files for use with the copy resource
vars/ #
main.yml # <-- variables associated with this role
defaults/ #
main.yml # <-- default lower priority variables for this role
meta/ #
main.yml # <-- role dependencies
library/ # roles can also include custom modules
module_utils/ # roles can also include custom module_utils
lookup_plugins/ # or other types of plugins, like lookup in this case
#
requirements.yml # required remote roles
```
9 changes: 9 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[defaults]
collections_paths = /etc/ansible/collections:/opt/ansible/collections:collections
roles_path = /etc/ansible/roles:/opt/ansible/roles:roles

# You’ll also need to make sure that requiretty is disabled
# in /etc/sudoers on the remote host, or become won’t work
# with pipelining enabled.
[ssh_connection]
pipelining = True
Empty file added bin/helpers/.gitkeep
Empty file.
14 changes: 14 additions & 0 deletions bin/helpers/user_repair.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# these commands are run as root
# if ansible user is somehow broken or missing, execute this script to repair it

useradd -m ansible -s /bin/bash
mkdir /home/ansible/.ssh
chmod 700 /home/ansible/.ssh
chown ansible:ansible /home/ansible/.ssh
echo "ansible ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/ansible
chmod 0440 /etc/sudoers.d/ansible
echo "< place key here >" >> /home/ansible/.ssh/authorized_keys
chmod 600 /home/ansible/.ssh/authorized_keys
chown ansible:ansible /home/ansible/.ssh/authorized_keys
11 changes: 11 additions & 0 deletions collections/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ignore everything in dir...
/*

# ... but current file...
!.gitignore

# ... external collections requirement file
!requirements.yml

# ... and configured custom/local collections
!ansible_collections/example_collection.*/
15 changes: 15 additions & 0 deletions collections/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
collections: []
# - name: ansible.netcommon
# version: 5.1.2
# - name: ansible.posix
# version: 1.5.4
# - name: ansible.utils
# version: 2.10.3
# - name: ansible.windows
# version: 1.14.0

# - name: community.docker
# version: 3.4.8
# - name: community.general
# version: 7.4.0
Empty file added filter_plugins/.gitkeep
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions inventories/production/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# to use short names in your inventory file
# uncomment the following lines.
# then you can use the hostname as the inventory name
# and do not need to specify the fqdn.

# host_domain: company.example.com
# ansible_host: "{{inventory_hostname}}.{{host_domain}}"

ansible_user: ansible
ansible_connection: ssh
ansible_become_method: sudo
ansible_python_interpreter: "/usr/bin/python3"

# if you want to use a specific ssh key
# ansible_ssh_private_key_file: /Users/rwaffen/.ssh/ansible
Empty file.
Empty file added inventories/production/hosts
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions inventories/staging/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# to use short names in your inventory file
# uncomment the following lines.
# then you can use the hostname as the inventory name
# and do not need to specify the fqdn.

# host_domain: company.example.com
# ansible_host: "{{inventory_hostname}}.{{host_domain}}"

ansible_user: ansible
ansible_connection: ssh
ansible_become_method: sudo
ansible_python_interpreter: "/usr/bin/python3"

# if you want to use a specific ssh key
# ansible_ssh_private_key_file: /Users/rwaffen/.ssh/ansible
Empty file.
Empty file added inventories/staging/hosts
Empty file.
Empty file added library/.gitkeep
Empty file.
Empty file added module_utils/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions playbooks/foo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Demo playbook
hosts: "{{ target_hosts | default('foo') }}"
roles:
- common
18 changes: 18 additions & 0 deletions playbooks/prepare_semaphore_exec_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
#
# This has to be run once the container from semaphore is up and running
# It will install the collections and pip packages needed for the playbooks
#

- name: "Dummy plug on localhost"
hosts: localhost
gather_facts: false
connection: local
tasks:
- name: "Install collections"
ansible.builtin.import_tasks:
file: "../tasks/install_collections.yml"

- name: "Install pip packages"
ansible.builtin.import_tasks:
file: "../tasks/install_pip.yml"
8 changes: 8 additions & 0 deletions playbooks/test_ssh_connection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: "Test SSH Connection"
hosts: "{{ target_hosts | default('all') }}"
gather_facts: false
tasks:
- name: Test we can logon to the servers and execute python with json lib.
ansible.builtin.ping:
register: ping_result
11 changes: 11 additions & 0 deletions roles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ignore everything in dir...
/*

# ... but current file...
!.gitignore

# ... external role requirement file
!requirements.yml

# ... and configured custom/local roles
!common/
2 changes: 2 additions & 0 deletions roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for common
Empty file added roles/common/files/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions roles/common/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for common
Empty file added roles/common/library/.gitkeep
Empty file.
Empty file.
40 changes: 40 additions & 0 deletions roles/common/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
galaxy_info:
author: betadots GmbH
description: Common role
company: betadots GmbH
issue_tracker_url: http://example.com/issue/tracker
license: BSD-3-Clause
min_ansible_version: "2.15.3"

# 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

# 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.
galaxy_tags: []

# List your role dependencies here, one per line. Be sure to remove the '[]',
# if you add dependencies to this list.
dependencies: []
Empty file.
2 changes: 2 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# tasks file for common
Empty file added roles/common/templates/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions roles/common/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

6 changes: 6 additions & 0 deletions roles/common/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Test
hosts: localhost
remote_user: root
roles:
- common
2 changes: 2 additions & 0 deletions roles/common/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for common
15 changes: 15 additions & 0 deletions roles/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
roles: []
### Galaxy
# - name: geerlingguy.ntp
# version: 2.3.3
# - name: geerlingguy.pip
# version: 2.2.0
# - name: geerlingguy.docker
# version: 6.2.0

# ### Github
# - name: mlangry.google-chrome
# version: 43198de
# scm: git
# src: https://github.com/mlangry/ansible-role-google-chrome.git
3 changes: 3 additions & 0 deletions site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Foo Demo Playbook
import_playbook: playbooks/foo.yml
Loading

0 comments on commit e8acdd3

Please sign in to comment.