Skip to content
Snippets Groups Projects
Commit 323d21a1 authored by Jörg Sachse's avatar Jörg Sachse
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
# CRLF vs. LF:
* text=auto
# make 'git diff' use ansible-vault for vault files, so you can see decrypted
# content if you have the password
*.vault diff=ansible-vault merge=binary
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)
# Redirect output to stderr.
exec 1>&2
# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi
# If there are whitespace errors, print the offending file names and fail.
# exec git diff-index --check --cached $against --
################################################################################
## Everything below this is customized, everything above is from the example. ##
################################################################################
### PREPARE
# Expand aliases and make alias command work in the bash script.
shopt -s expand_aliases
REPOPATH="$(git rev-parse --show-toplevel)"
GREP_CMD='grep -Rn --color'
GREP_EXCLUDES="--exclude-dir=\.git --exclude-dir=\.githooks --exclude=*\.example"
### YAMLLINT stage
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
YAML_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".yml$")
if [[ ${YAML_FILES} != "" ]]; then
for file in ${YAML_FILES}; do
yamllint "${file}"
if [[ ${?} -ne 0 ]]; then
exit 1
fi
done
fi && echo "SUCCESS: Yamllint stage."
### VAULT detection stage
VAULT_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".vault$")
if [[ ${VAULT_FILES} != "" ]]; then
echo "ERROR: Vaultfiles found:"
for file in ${VAULT_FILES}; do
echo "- ${file}"
done
exit 1
fi
# https://docs.ansible.com/ansible/latest/user_guide/vault.html#vault-format
if [[ ${STAGED_FILES} != "" ]]; then
for file in ${STAGED_FILES}; do
grep -e "\$ANSIBLE_VAULT;[[:digit:]]\.[[:digit:]];AES256" "${file}"
[[ ${?} -eq 0 ]] && echo "ERROR: Ansible-Vault in String found in file '${file}'." && exit 1
done
fi
echo "SUCCESS: Vault detection stage."
### URL detection stage
${GREP_CMD} ${GREP_EXCLUDES} -e "http[s]*.*git.*SLUB" -e "http[s]*.*git.*slub" -e "git@" "${REPOPATH}"
if [[ ${?} -eq 0 ]]; then
echo "ERROR: found internal URLs."
exit 1;
fi
echo "SUCCESS: URL detection stage."
### IP address detection stage
# This is pretty basic regex matching, but it's a start.
IP_REGEX='[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
${GREP_CMD} ${GREP_EXCLUDES} -e "${IP_REGEX}" "${REPOPATH}" | grep -v "127.0.0"
if [[ ${?} -eq 0 ]]; then
echo "ERROR: found IP address."
exit 1;
fi
echo "SUCCESS: IP address detection stage."
### SSH-Key detection stage
${GREP_CMD} ${GREP_EXCLUDES} -e "ssh-[dr]sa " "${REPOPATH}"
if [[ ${?} -eq 0 ]]; then
echo "ERROR: found SSH key."
exit 1;
fi
echo "SUCCESS: SSH Key detection stage."
### DONE
# Return explicit 0.
exit 0;
# Compiled source #
###################
*.bin
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
__pycache__
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.tar.gz
*.tgz
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Linux packages #
##################
*.deb
*.rpm
# Ansible specific files #
##########################
*.retry
*.vault
# Vim #
#######
# swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# session
Session.vim
# temporary
.netrwhist
# auto-generated tag files
tags
# Vagrant #
###########
.vagrant/
*.box
# Build #
#########
build/
iso/
# temporary files #
###################
# A fresh version of this file has to be provided by the administrator each
# time new systems should be installed. Hence, it's not suitable for version
# control.
vars/network.yml
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
\ No newline at end of file
---
# Based on ansible-lint config
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
This diff is collapsed.
# Ansible-Role "ansible_lza_create_rhel_iso"
## Description
This role provides all necessary tasks to create RHEL 7 installation ISO images to create servers for SLUBArchiv before bootstrapping them for a non-root user to take over.
## Prerequisites
To use this role, the following software must be installed on your workstation:
* ansible
To deploy this role to a managed host, the following software must be installed on the target:
* Python3
* SSHd
## Quick start
```
ansible-playbook site.yml -b -K
```
## General usage
Most options already have sensible defaults in `ansible.cfg`. However, you can override these defaults using CLI options/flags if you want to.
To simply run the playbook, just call the `site.yml` playbook like this:
```
ansible-playbook site.yml -u <username>
```
If you want to limit the execution to a subset of all hosts that are listed in the inventory, use the `-l` or `--limit` option like this:
```
ansible-playbook site.yml -l <hostna*>
ansible-playbook site.yml -l <hostname>
ansible-playbook site.yml -l <hostname1>:<hostname2>:...
ansible-playbook site.yml -l <inventory_group>
ansible-playbook site.yml --limit=<hostna*>
```
If you do not have Vault password files in the directory above the role direcory, you have to give the Vault password before execution:
```
ansible-playbook site.yml --ask-vault-pass
```
You can use your own inventory file by adding the `-i` or `--inventory=INVENTORY` option:
```
ansible-playbook site.yml -i inventory.yml
ansible-playbook site.yml --inventory=inventory.yml
```
Tasks in this role have been tagged to enable users to only run subsets of tasks. This can be leveraged to decrease run times or run only certain tasks after small changes.
To list all available tags, use:
```
ansible-playbook site.yml --list-tags
```
You can then run only certain tagged tasks by using the `--tags` option:
```
ansible-playbook site.yml -t tag1,tag2,...,tagN
ansible-playbook site.yml --tags=tag1,tag2,...,tagN
```
For more help with ansible-playbook, use the `--help` flag.
## Testing the role
Tests have been implemented using the Molecule framework. The details on using the test suite are described below `molecule/`.
## Variables
Many variables have been "hidden" in encrypted Ansible Vaults. For security reasons, these Vaults are maintained in a separate private internal repository of SLUB's Git. However, in order to better understand the data within the vaults, you can find `\*.vault.example` files below the `vars/` directory.
## git configuration
Just run the `setup_gitconfig.sh` script that comes with the repo to correctly setup all necessary local Git configurations.
## Author Information
If you have any comments or find bugs, please contact langzeitarchiv@slub-dresden.de or issue a pull request.
[defaults]
# Path to default inventory file
# Administrators can override this by using the "-i <inventoryfile>" CLI
# argument.
inventory = ../ansible_vaults/inventory.yml
# Remote user name
# As this role is supposed to run locally, we don't assign a remote user. Use
# your own local non-root user where needed.
#remote_user = non-root
# By default, ansible will use the 'linear' strategy but you may want to try
# another one
strategy = free
# Don't like cows? that's unfortunate.
# Set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
nocows = 1
# Custom role path that guarantees roles are always found, no matter where a
# user checks them out.
roles_path = ../:~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
[inventory]
# Ignore these extensions when parsing a directory as inventory source.
ignore_extensions = .pyc, .pyo, .swp, .bak, ~, .rpm, .md, .txt, ~, .orig, .ini, .cfg, .retry
[ssh_connection]
# Enabling pipelining reduces the number of SSH operations required to
# execute a module on the remote server. This can result in a significant
# performance improvement when enabled, however when using "sudo:" you must
# first disable 'requiretty' in /etc/sudoers
# By default, this option is disabled to preserve compatibility with
# sudoers configurations that have requiretty (the default on many distros).
#pipelining = True
pipelining = False
---
# defaults file for ansible_lza_create_rhel_iso
---
# handlers file for ansible_lza_create_rhel_iso
---
galaxy_info:
author: Jörg Sachse
description: role to create RedHat 7 installation ISOs.
company: SLUB Dresden
# 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 Some suggested licenses: - BSD
# (default) - MIT - GPLv2 - GPLv3 - Apache - CC-BY
license: GPLv3
min_ansible_version: 2.5
# If this a Container Enabled role, provide the minimum Ansible Container version. min_ansible_container_version: Optionally specify the branch Galaxy will use when accessing the GitHub repo
#for this role. During role install, if no tags are available, Galaxy will use this branch. During import Galaxy will access files on this branch. If Travis integration is configured, only
#notifications for this branch will be accepted. Otherwise, in all cases, the repo's default branch (usually master) will be used. github_branch:
#
# 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
platforms:
- name: RedHat
versions:
- 7
- name: Debian
versions:
- 10
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: []
*******
Delegated driver installation guide
*******
Requirements
============
This driver is delegated to the developer. Up to the developer to implement
requirements.
Install
=======
This driver is delegated to the developer. Up to the developer to implement
requirements.
---
- name: Converge
hosts: all
tasks:
- name: "Include ansible_lza_create_rhel_iso"
include_role:
name: "ansible_lza_create_rhel_iso"
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
# TODO: Developer must implement and populate 'server' variable
- when: server.changed | default(false) | bool
block:
- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ }}",
'address': "{{ }}",
'user': "{{ }}",
'port': "{{ }}",
'identity_file': "{{ }}", }
with_items: "{{ server.results }}"
register: instance_config_dict
- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
- name: Dump instance config
copy:
content: |
# Molecule managed
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ molecule_no_log }}"
tasks:
# Developer must implement.
# Mandatory configuration for Molecule to function.
- name: Populate instance config
set_fact:
instance_conf: {}
- name: Dump instance config
copy:
content: |
# Molecule managed
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
when: server.changed | default(false) | bool
---
dependency:
name: galaxy
driver:
name: delegated
platforms:
- name: instance
provisioner:
name: ansible
verifier:
name: ansible
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
assert:
that: true
#!/usr/bin/env bash
set -ex
# Change the path that Git expects the hooks to be in, so we can track the hooks
# within the repository (as the default `.git/` directory is not tracked).
git config --local core.hooksPath .githooks/
# To be able to run `git diff` on Ansible Vault files, please set you local
# `git/config` files as described in (https://stackoverflow.com/a/52863794) for
# the `~/.gitconfig` file or just blindly follow the instructions there to set
# it for you Git installation as a whole.
git config --local core.attributesfile "../.gitattributes"
git config --local diff.ansible-vault.textconv "ansible-vault view"
site.yml 0 → 100644
---
- hosts: localhost
connection: local
vars:
- ISO: "RHEL79"
vars_prompt:
- name: install_hostname
prompt: "What's the hostname of the system that you're trying to install? Use ONLY the hostname, NOT the FQDN!"
private: false
pre_tasks:
- name: Verify that the installed version of Ansible meets this playbook's version requirements.
assert:
that: "ansible_version.full is version_compare('2.5', '>=')"
msg: >
"You must update Ansible to at least 2.5 to use this playbook."
# Collect facts from remote system? Possible values: true, false
gather_facts: true
# Gather only certain subsects of facts. Ansible supports network, hardware, virtual, facter, ohai as subset.
gather_subset:
- network
- virtual
- hardware
# any_error_fatal will mark all the hosts as failed if fails and immediately abort the playbook execution. Possible values: true, false
any_errors_fatal: false
# max_fail_percentage allows you to abort the play if certain threshold of failures have been reached.
max_fail_percentage: 30
serial: 30
# hide sensitive information in verbose/debugging output from others. Possible values: true, false
no_log: false
# execution strategy, possible values: debug, linear, serial, free (https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html)
strategy: linear
roles:
- { role: ansible_lza_create_rhel_iso }
---
### PREPARATION
- name: create build directory
file:
path: "{{ playbook_dir }}/build/"
state: directory
- name: mount boot ISO
mount:
fstype: "iso9660"
opts: "loop"
path: "{{ playbook_dir }}/iso/"
src: "{{ playbook_dir }}/rhel-server-7.9-x86_64-dvd.iso"
fstab: "/tmp/fstab"
state: mounted
- name: copy ISO contents
shell:
cmd: 'cp -avRf "{{ playbook_dir }}/iso" "{{ playbook_dir }}/build"'
ignore_errors: true
- name: check if listfile for networking exists...
find:
paths: "{{ playbook_dir }}/vars/"
patterns: "network.yml"
register: result_network
- name: ... and bail out if config file doesn't exist
fail:
msg: "The required config file 'vars/network.yml' couldn't be found. Please refer to vars/network.yml.example for further documentation."
when: "result_network.matched < 1"
- name: include networking variables
include_vars: "{{ item.path }}"
loop: "{{ result_network.files }}"
### CREATE CONFIGS
- name: write Kickstart files
template:
src: "kickstart.cfg.j2"
dest: "build/iso/{{ item.hostname }}.cfg"
loop: "{{ hosts }}"
- name: template isolinux config
template:
src: "isolinux.cfg.j2"
dest: "{{ playbook_dir }}/build/iso/isolinux/isolinux.cfg"
loop: "{{ hosts }}"
when: "install_hostname in item.hostname"
### CREATE ISO INSTALLATION IMAGE
- name: create ISO image
command:
cmd: 'xorrisofs -output {{ playbook_dir }}/build/{{ ISO }}.iso -eltorito-boot isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -volid "{{ ISO }}" -rational-rock {{ playbook_dir }}/build/iso/'
chdir: "{{ playbook_dir }}/build/iso/"
- name: make ISO bootable
command: 'isohybrid -v {{ playbook_dir }}/build/{{ ISO }}.iso'
### CLEANUP
- name: umount boot ISO
mount:
path: "{{ playbook_dir }}/iso"
state: unmounted
- name: clean up
file:
path: "{{ item }}"
state: absent
loop:
- "/tmp/fstab"
- "{{ playbook_dir }}/iso/"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment