initial commit

This commit is contained in:
Phil
2019-09-20 15:08:16 -04:00
commit e42131e407
29 changed files with 1761 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.python-version

5
master.yml Normal file
View File

@ -0,0 +1,5 @@
- hosts: localhost
roles:
- role: gantsign.oh-my-zsh
users:
- username: pskentelbery

View File

@ -0,0 +1,19 @@
# EditorConfig: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Defaults for all editor files
[*]
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
# Files with a smaller indent
[*.yml]
indent_size = 2
# Jinja2 template files
[*.j2]
end_of_line = lf

43
roles/gantsign.oh-my-zsh/.gitattributes vendored Normal file
View File

@ -0,0 +1,43 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
.gitignore text
.gitattributes text
*.xml text
*.yml text
*.yaml text
*.json text
*.txt text
*.md text
*.htm text
*.html text
*.xhtml text
*.js text
*.ts text
*.css text
*.less text
*.scss text
*.cfg text
LICENSE text
# Declare files that will always have CRLF line endings on checkout.
*.bat text eol=crlf
*.cmd text eol=crlf
# Declare files that will always have LF line endings on checkout.
*.sh text eol=lf
*.service eol=lf
*.conf eol=lf
*.desktop eol=lf
*.j2 eol=lf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.eot binary
*.tff binary
*.woff binary

250
roles/gantsign.oh-my-zsh/.gitignore vendored Normal file
View File

@ -0,0 +1,250 @@
# Created by https://www.gitignore.io/api/windows,linux,osx,vim,emacs,intellij,eclipse,visualstudiocode,ansible
### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
### OSX ###
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# Eclipse Core
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# JDT-specific (Eclipse Java Development Tools)
.classpath
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
### Ansible ###
*.retry
####################
### Custom rules ###
####################
### Molecule ###
__pycache__
.cache
.molecule

View File

@ -0,0 +1 @@
2.8.2

View File

@ -0,0 +1 @@
3.5.0

View File

@ -0,0 +1 @@
2.20.2

View File

@ -0,0 +1 @@
2.7.15

View File

@ -0,0 +1,39 @@
---
language: python
python: '2.7'
env:
global:
- MOLECULEW_USE_SYSTEM=true
matrix:
# Spin off separate builds for each of the following versions of Ansible
- MOLECULEW_ANSIBLE=2.6.18
- MOLECULEW_ANSIBLE=2.8.2
# Require the standard build environment
sudo: required
# Require Ubuntu 14.04
dist: trusty
# Require Docker
services:
- docker
install:
# Install dependencies
- ./moleculew wrapper-install
# Display versions
- ./moleculew wrapper-versions
script:
- ./moleculew test
branches:
only:
- master
- /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([\.\-].*)?$/
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -0,0 +1,11 @@
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
line-length: disable
truthy: disable

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 GantSign Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,141 @@
Ansible Role: Oh My Zsh
=======================
[![Build Status](https://travis-ci.org/gantsign/ansible-role-oh-my-zsh.svg?branch=master)](https://travis-ci.org/gantsign/ansible-role-oh-my-zsh)
[![Ansible Galaxy](https://img.shields.io/badge/ansible--galaxy-gantsign.oh--my--zsh-blue.svg)](https://galaxy.ansible.com/gantsign/oh-my-zsh)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/gantsign/ansible-role-oh-my-zsh/master/LICENSE)
Role to download, install and configure [Oh-My-Zsh](http://ohmyz.sh/).
**Note:** you may be better off using the alternative
[gantsign.ansible_role_antigen](https://galaxy.ansible.com/gantsign/antigen)
role that can install third-party Zsh plugins as well as installing Oh My Zsh
and its plugins.
Requirements
------------
* Ansible >= 2.6
* Linux Distribution
* Debian Family
* Debian
* Jessie (8)
* Stretch (9)
* Ubuntu
* Trusty (14.04)
* Xenial (16.04)
* Bionic (18.04)
* RedHat Family
* CentOS
* 7
* Fedora
* 28
* SUSE Family
* openSUSE
* 15.0
* Note: other versions are likely to work but have not been tested.
Role Variables
--------------
The following variables will change the behavior of this role (default values
are shown below):
```yaml
# Default theme
oh_my_zsh_theme: robbyrussell
# Default plugins
oh_my_zsh_plugins:
- git
# User configuration
# Important: oh-my-zsh is installed per user so you need to specify the users to install it for.
users:
- username: example1
oh_my_zsh:
theme: robbyrussell
plugins:
- git
- username: example2
oh_my_zsh:
theme: robbyrussell
plugins:
- git
- mvn
```
Example Playbook
----------------
```yaml
- hosts: servers
roles:
- role: gantsign.oh-my-zsh
users:
- username: example
```
More Roles From GantSign
------------------------
You can find more roles from GantSign on
[Ansible Galaxy](https://galaxy.ansible.com/gantsign).
Development & Testing
---------------------
This project uses [Molecule](http://molecule.readthedocs.io/) to aid in the
development and testing; the role is unit tested using
[Testinfra](http://testinfra.readthedocs.io/) and
[pytest](http://docs.pytest.org/).
To develop or test you'll need to have installed the following:
* Linux (e.g. [Ubuntu](http://www.ubuntu.com/))
* [Docker](https://www.docker.com/)
* [Python](https://www.python.org/) (including python-pip)
* [Ansible](https://www.ansible.com/)
* [Molecule](http://molecule.readthedocs.io/)
Because the above can be tricky to install, this project includes
[Molecule Wrapper](https://github.com/gantsign/molecule-wrapper). Molecule
Wrapper is a shell script that installs Molecule and it's dependencies (apart
from Linux) and then executes Molecule with the command you pass it.
To test this role using Molecule Wrapper run the following command from the
project root:
```bash
./moleculew test
```
Note: some of the dependencies need `sudo` permission to install.
License
-------
MIT
Author Information
------------------
John Freeman
GantSign Ltd.
Company No. 06109112 (registered in England)

View File

@ -0,0 +1,7 @@
---
# Default theme
oh_my_zsh_theme: robbyrussell
# Default plugins
oh_my_zsh_plugins:
- git

View File

@ -0,0 +1,4 @@
---
- name: dpkg-reconfigure console-setup
become: yes
command: /usr/sbin/dpkg-reconfigure -f noninteractive console-setup

View File

@ -0,0 +1,2 @@
install_date: Fri Sep 20 01:56:10 2019
version: 2.2.1

View File

@ -0,0 +1,32 @@
---
galaxy_info:
author: John Freeman
description: Role for installing and configuring oh-my-zsh.
company: GantSign Ltd.
license: MIT
min_ansible_version: 2.6
platforms:
- name: EL
versions:
- 7
- name: Fedora
versions:
- 28
- name: opensuse
versions:
- 15.0
- name: Ubuntu
versions:
- trusty
- xenial
- bionic
- name: Debian
versions:
- jessie
- stretch
galaxy_tags:
- ohmyzsh
- zsh
- shell
- development
dependencies: []

View File

@ -0,0 +1,14 @@
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

View File

@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******
Requirements
============
* Docker Engine
Install
=======
Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
.. code-block:: bash
$ pip install 'molecule[docker]'

View File

@ -0,0 +1,38 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: ansible-role-oh-my-zsh-debian-min
image: debian:8
- name: ansible-role-oh-my-zsh-debian-max
image: debian:9
- name: ansible-role-oh-my-zsh-ubuntu-min
image: ubuntu:14.04
- name: ansible-role-oh-my-zsh-ubuntu-max
image: ubuntu:18.04
- name: ansible-role-oh-my-zsh-centos
image: centos:7
- name: ansible-role-oh-my-zsh-fedora
image: fedora:28
- name: ansible-role-oh-my-zsh-opensuse
image: opensuse/leap:15.0
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8

View File

@ -0,0 +1,39 @@
---
- name: Converge
hosts: all
pre_tasks:
- name: create test users
become: yes
user:
name: '{{ item }}'
home: '/home/{{ item }}'
createhome: yes
with_items:
- test_usr1
- test_usr2
- name: install console-setup file
become: yes
copy:
src: tests/console-setup.sh
dest: /etc/default/console-setup
force: no
owner: root
group: root
mode: 'u=rwx,go=r'
roles:
- role: ansible-role-oh-my-zsh
oh_my_zsh_theme: test_theme1
oh_my_zsh_plugins:
- test_plugin1
- test_plugin2
users:
- username: test_usr1
- username: test_usr2
oh_my_zsh:
theme: test_theme2
plugins:
- test_plugin3
- test_plugin4

View File

@ -0,0 +1,16 @@
# CONFIGURATION FILE FOR SETUPCON
# Consult the console-setup(5) manual page.
ACTIVE_CONSOLES="/dev/tty[1-6]"
CHARMAP="ISO-8859-1"
CODESET="Lat15"
FONTFACE="VGA"
FONTSIZE="8x16"
VIDEOMODE=
# The following is an example how to use a braille font
# FONT='lat9w-08.psf.gz brl-8x8.psf'

View File

@ -0,0 +1,45 @@
import pytest
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.mark.parametrize('username', [
'test_usr1',
'test_usr2',
])
def test_oh_my_zsh_install(host, username):
oh_my_zsh = host.file('/home/' + username + '/.oh-my-zsh')
assert oh_my_zsh.exists
assert oh_my_zsh.is_directory
assert oh_my_zsh.user == username
assert oh_my_zsh.group in [username, 'users']
@pytest.mark.parametrize('username,theme,plugins', [
('test_usr1', 'test_theme1', 'test_plugin1 test_plugin2'),
('test_usr2', 'test_theme2', 'test_plugin3 test_plugin4'),
])
def test_oh_my_zsh_config(host, username, theme, plugins):
zshrc = host.file('/home/' + username + '/.zshrc')
assert zshrc.exists
assert zshrc.is_file
assert zshrc.user == username
assert zshrc.group in [username, 'users']
assert zshrc.contains(theme)
assert zshrc.contains(plugins)
def test_console_setup(host):
# console-setup is Debian family specific
if host.file('/etc/debian_version').exists:
setup = host.file('/etc/default/console-setup')
assert setup.exists
assert setup.is_file
assert setup.user == 'root'
assert setup.group == 'root'
assert setup.contains('CHARMAP="UTF-8"')

View File

@ -0,0 +1,792 @@
#!/usr/bin/env bash
# MIT License
#
# Copyright (c) 2018 GantSign Ltd.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Molecule Wrapper the wrapper script for Molecule
# https://github.com/gantsign/molecule-wrapper
set -e
WRAPPER_VERSION=0.9.9
VERSION_DIR='.moleculew'
PYTHON_VERSION_FILE="$VERSION_DIR/python_version"
ANSIBLE_VERSION_FILE="$VERSION_DIR/ansible_version"
DOCKER_LIB_VERSION_FILE="$VERSION_DIR/docker_lib_version"
MOLECULE_VERSION_FILE="$VERSION_DIR/molecule_version"
BUILD_DEPENDENCIES_INSTALLLED=false
PYENV_INSTALLED=false
ANSIBLE_VERSION=''
DOCKER_LIB_VERSION=''
MOLECULE_VERSION=''
PYTHON_VERSION=''
USE_SYSTEM_DEPENDENCIES=false
PRE_ARGS=()
MOLECULE_CMD=''
POST_ARGS=()
export PATH="$HOME/.pyenv/bin:$HOME/.local/bin:$PATH"
hr() {
for ((i = 1; i <= 80; i++)); do
printf '*'
done
echo ''
}
banner() {
hr
echo "$1"
hr
}
run_as_root() {
if [[ $EUID -eq 0 ]]; then
"$@"
elif [ -x "$(command -v sudo)" ]; then
sudo "$@"
else
echo "Error: sudo is not installed" >&2
exit 1
fi
}
build_dependencies_present() {
if [[ $BUILD_DEPENDENCIES_INSTALLLED == true ]]; then
return
fi
if [[ $USE_SYSTEM_DEPENDENCIES == true ]]; then
return
fi
# https://github.com/pyenv/pyenv/wiki/common-build-problems
if [[ -x "$(command -v apt-get)" ]]; then
banner 'Installing build dependencies'
run_as_root apt-get update
run_as_root apt-get install --assume-yes \
make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev \
git jq
echo ''
elif [[ -x "$(command -v dnf)" ]]; then
banner 'Installing build dependencies'
run_as_root dnf install \
zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel \
openssl-devel xz xz-devel libffi-devel \
git which curl jq
echo ''
elif [[ -x "$(command -v yum)" ]]; then
banner 'Installing build dependencies'
run_as_root yum install \
zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel \
openssl-devel xz xz-devel libffi-devel \
git which curl jq
echo ''
elif [[ -x "$(command -v zypper)" ]]; then
banner 'Installing build dependencies'
run_as_root zypper install \
zlib-devel bzip2 libbz2-devel readline-devel sqlite3 sqlite3-devel \
libopenssl-devel xz xz-devel \
git which curl jq
echo ''
fi
BUILD_DEPENDENCIES_INSTALLLED=true
}
pyenv_present() {
if [[ $PYENV_INSTALLED == true ]]; then
return
fi
if [[ $USE_SYSTEM_DEPENDENCIES == true ]]; then
return
fi
if [[ -x "$(command -v pyenv)" ]]; then
PYENV_INSTALLED=true
return
fi
build_dependencies_present
banner "Installing pyenv for user $USER"
bash <(curl --location https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer)
echo ''
PYENV_INSTALLED=true
}
query_latest_python_version2() {
pyenv_present
PYTHON_VERSION="$(~/.pyenv/plugins/python-build/bin/python-build --definitions | grep --color=never '^2\.' | grep --invert-match '\-dev$' | tail -1)"
}
query_latest_python_version3() {
pyenv_present
PYTHON_VERSION="$(~/.pyenv/plugins/python-build/bin/python-build --definitions | grep --color=never '^3\.' | grep --invert-match '\-dev$' | tail -1)"
}
query_latest_package_version() {
if [[ ! -x "$(command -v curl)" ]]; then
build_dependencies_present
fi
if [[ ! -x "$(command -v jq)" ]]; then
build_dependencies_present
fi
if [[ ! -x "$(command -v curl)" ]]; then
echo 'Error: curl is not installed.' >&2
exit 1
fi
if [[ ! -x "$(command -v jq)" ]]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi
local version
# shellcheck disable=SC2034
version=$(curl --fail --silent --show-error --location "https://pypi.org/pypi/$2/json" | jq --raw-output '.info.version')
eval "$1=\"\$version\""
}
docker_present() {
if [[ -x "$(command -v docker)" ]]; then
return
fi
if [[ $USE_SYSTEM_DEPENDENCIES == true ]]; then
echo 'Error: docker is not installed.' >&2
exit 1
fi
build_dependencies_present
banner 'Installing Docker'
sh <(curl --fail --silent --show-error --location https://get.docker.com)
run_as_root usermod --append --groups docker "$USER"
banner "User '$USER' has been added to the 'docker' group. Logout/restart and log back in for changes to take effect."
exit
}
python_present() {
if [[ $PYTHON_VERSION == system ]]; then
if [[ ! -x "$(command -v python)" ]]; then
echo 'Error: python is not installed.' >&2
exit 1
fi
if [[ ! -x "$(command -v pip)" ]]; then
echo 'Error: pip is not installed.' >&2
exit 1
fi
if [[ ! -x "$(command -v which)" ]]; then
echo 'Error: which is not installed.' >&2
exit 1
fi
PYTHON_EXE="$(which python)"
else
if [[ ! -x "$(command -v git)" ]]; then
echo 'Error: git is not installed.' >&2
exit 1
fi
pyenv_present
export PYENV_VERSION="$PYTHON_VERSION"
if [[ ! -d "$HOME/.pyenv/versions/$PYTHON_VERSION" ]]; then
build_dependencies_present
banner "Making Python version $PYTHON_VERSION available using pyenv"
pyenv install "$PYTHON_VERSION"
echo ''
fi
eval "$(pyenv init -)"
PYTHON_EXE="$(pyenv which python)"
fi
}
virtualenv_presant() {
if [[ ! -x "$(command -v virtualenv)" ]]; then
banner "Installing virtualenv for user $USER"
pip install --user virtualenv
echo ''
fi
}
install_ansible() {
banner "Installing Ansible $ANSIBLE_VERSION into virtualenv $VIRTUAL_ENV"
pip install "ansible==$ANSIBLE_VERSION"
echo ''
}
install_docker_lib() {
banner "Installing Python Docker $DOCKER_LIB_VERSION into virtualenv $VIRTUAL_ENV"
pip install "docker==$DOCKER_LIB_VERSION"
echo ''
}
install_molecule() {
banner "Installing Molecule $MOLECULE_VERSION into virtualenv $VIRTUAL_ENV"
pip install "molecule==$MOLECULE_VERSION"
echo ''
}
wrapper_clean() {
local MOLECULE_WRAPPER_HOME="$HOME/.moleculew"
read -r -p "Delete ${MOLECULE_WRAPPER_HOME} (y/n)? " yn
case $yn in
[Yy]|YES|yes|Yes)
rm -rf "$MOLECULE_WRAPPER_HOME";
exit
;;
*)
exit
;;
esac
}
wrapper_upgrade() {
curl --fail --silent --show-error --location --output moleculew.new \
'https://raw.githubusercontent.com/gantsign/molecule-wrapper/master/moleculew' \
&& chmod 'u+x' moleculew.new \
&& mv --force moleculew.new moleculew
local NEW_VERSION
NEW_VERSION="$(./moleculew wrapper-version)"
if [ "$WRAPPER_VERSION" != "$NEW_VERSION" ]; then
echo "Upgraded wrapper from version $WRAPPER_VERSION to $NEW_VERSION"
else
echo "You are already using the latest version"
fi
exit
}
wrapper_version() {
echo "$WRAPPER_VERSION"
exit
}
print_versions() {
echo "Python: $PYTHON_VERSION"
echo "Ansible: $ANSIBLE_VERSION"
echo "Python Docker library: $DOCKER_LIB_VERSION"
echo "Molecule: $MOLECULE_VERSION"
}
wrapper_versions() {
detemine_versions
print_versions
exit
}
wrapper_freeze() {
detemine_versions
banner 'Freezing versions'
mkdir -p "$VERSION_DIR"
echo "$PYTHON_VERSION" > "$PYTHON_VERSION_FILE"
echo "$ANSIBLE_VERSION" > "$ANSIBLE_VERSION_FILE"
echo "$DOCKER_LIB_VERSION" > "$DOCKER_LIB_VERSION_FILE"
echo "$MOLECULE_VERSION" > "$MOLECULE_VERSION_FILE"
print_versions
exit
}
wrapper_unfreeze() {
banner 'Un-freezing versions'
if [[ -f "$PYTHON_VERSION_FILE" ]]; then
rm --verbose "$PYTHON_VERSION_FILE"
fi
if [[ -f "$ANSIBLE_VERSION_FILE" ]]; then
rm --verbose "$ANSIBLE_VERSION_FILE"
fi
if [[ -f "$DOCKER_LIB_VERSION_FILE" ]]; then
rm --verbose "$DOCKER_LIB_VERSION_FILE"
fi
if [[ -f "$MOLECULE_VERSION_FILE" ]]; then
rm --verbose "$MOLECULE_VERSION_FILE"
fi
exit
}
wrapper_upgrade_versions() {
detemine_versions
banner 'Upgrading versions'
local CURRENT_PYTHON_VERSION="$PYTHON_VERSION"
local CURRENT_ANSIBLE_VERSION="$ANSIBLE_VERSION"
local CURRENT_DOCKER_LIB_VERSION="$DOCKER_LIB_VERSION"
local CURRENT_MOLECULE_VERSION="$MOLECULE_VERSION"
query_latest_python_version2
query_latest_package_version ANSIBLE_VERSION ansible
query_latest_package_version DOCKER_LIB_VERSION docker
query_latest_package_version MOLECULE_VERSION molecule
echo ''
echo 'New versions:'
if [[ "$CURRENT_PYTHON_VERSION" == "$PYTHON_VERSION" ]]; then
echo "Python: $CURRENT_PYTHON_VERSION (no change)"
else
echo "Python: $CURRENT_PYTHON_VERSION -> $PYTHON_VERSION"
fi
if [[ "$CURRENT_ANSIBLE_VERSION" == "$ANSIBLE_VERSION" ]]; then
echo "Ansible: $CURRENT_ANSIBLE_VERSION (no change)"
else
echo "Ansible: $CURRENT_ANSIBLE_VERSION -> $ANSIBLE_VERSION"
fi
if [[ "$CURRENT_DOCKER_LIB_VERSION" == "$DOCKER_LIB_VERSION" ]]; then
echo "Python Docker library: $CURRENT_DOCKER_LIB_VERSION (no change)"
else
echo "Python Docker library: $CURRENT_DOCKER_LIB_VERSION -> $DOCKER_LIB_VERSION"
fi
if [[ "$CURRENT_MOLECULE_VERSION" == "$MOLECULE_VERSION" ]]; then
echo "Molecule: $CURRENT_MOLECULE_VERSION (no change)"
else
echo "Molecule: $CURRENT_MOLECULE_VERSION -> $MOLECULE_VERSION"
fi
echo ''
wrapper_freeze
}
wrapper_help() {
activate_virtualenv
molecule --help
echo "
Molecule Wrapper
Additional options:
--ansible VERSION Use the specified version of Ansible
--docker-lib VERSION Use the specified version of the Python Docker
library
--molecule VERSION Use the specified version of Molecule
--python VERSION Use the specified version of Python
--use-system-dependencies Use system dependencies
Additional commands:
wrapper-clean Removes all the wrapper virtual environments
wrapper-freeze Freezes the dependency versions being used
wrapper-unfreeze Un-freezes the dependency versions
wrapper-upgrade Upgrades the Molecule Wrapper to the latest version
wrapper-upgrade-versions Upgrades any frozen dependency versions
wrapper-version Displays the current version of Molecule Wrapper
"
}
query_package_versions() {
local package_name="$1"
local min_version="$2"
if [[ ! -x "$(command -v curl)" ]]; then
build_dependencies_present > /dev/null
fi
if [[ ! -x "$(command -v jq)" ]]; then
build_dependencies_present > /dev/null
fi
if [[ ! -x "$(command -v curl)" ]]; then
echo 'Error: curl is not installed.' >&2
exit 1
fi
if [[ ! -x "$(command -v jq)" ]]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi
if [[ ! -x "$(command -v sort)" ]]; then
echo 'Error: sort is not installed.' >&2
exit 1
fi
for i in $(curl --fail --silent --show-error \
--location "https://pypi.org/pypi/$package_name/json" \
| jq --raw-output ".releases | keys | .[], \"$min_version.\"" \
| grep --invert-match '[a-zA-Z]' \
| sort --version-sort --reverse) ; do
if [[ "$i" == "$min_version." ]]; then
break
fi
echo "$i"
done
}
wrapper_options_ansible() {
echo 'latest'
query_package_versions 'ansible' '2.2'
}
wrapper_options_docker_lib() {
echo 'latest'
query_package_versions 'docker' '3.0'
}
wrapper_options_molecule() {
echo 'latest'
query_package_versions 'molecule' '2.0'
}
wrapper_options_python() {
if [[ ! -x "$(command -v sort)" ]]; then
echo 'Error: sort is not installed.' >&2
exit 1
fi
pyenv_present > /dev/null
local min_version='2.7'
echo 'latest'
for i in $( (echo "$min_version." && \
~/.pyenv/plugins/python-build/bin/python-build --definitions) \
| grep --color=never '^[0-9]' \
| grep --invert-match '\-dev$' \
| sort --version-sort --reverse) ; do
if [[ "$i" == "$min_version." ]]; then
break
fi
echo "$i"
done
}
wrapper_options_scenario() {
if [ -f 'moleculew' ]; then
activate_virtualenv > /dev/null
fi
python << EOF
import os
import sys
import six
import yaml
molecule_dir = 'molecule'
if not os.path.isdir(molecule_dir):
sys.exit()
scenarios = []
default = False
for filename in os.listdir(molecule_dir):
scenario_dir = os.path.join(molecule_dir, filename)
if not os.path.isdir(scenario_dir):
continue
molecule_yaml = os.path.join(scenario_dir, 'molecule.yml')
if not os.path.isfile(molecule_yaml):
continue
with open(molecule_yaml, 'r') as stream:
try:
contents = yaml.load(stream)
except yaml.YAMLError as exc:
continue
if not isinstance(contents, dict):
continue
scenario = contents.get('scenario')
if scenario is None:
continue
if not isinstance(scenario, dict):
continue
name = scenario.get('name')
if name is None:
continue
if not isinstance(name, six.string_types):
continue
if name == 'default':
default = True
else:
scenarios.append(name)
scenarios.sort()
if default:
scenarios.append('default')
for scenario in scenarios:
print(scenario)
EOF
}
wrapper_virtualenv() {
activate_virtualenv > /dev/null
echo "$VIRTUAL_ENV"
}
parse_args() {
set +e
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--python=*)
PYTHON_VERSION="${1#*=}"
shift
;;
--python)
shift
PYTHON_VERSION="$1"
shift
;;
--ansible=*)
ANSIBLE_VERSION="${1#*=}"
shift
;;
--ansible)
shift
ANSIBLE_VERSION="$1"
shift
;;
--docker-lib=*)
DOCKER_LIB_VERSION="${1#*=}"
shift
;;
--docker-lib)
shift
DOCKER_LIB_VERSION="$1"
shift
;;
--molecule=*)
MOLECULE_VERSION="${1#*=}"
shift
;;
--molecule)
shift
MOLECULE_VERSION="$1"
shift
;;
--use-system-dependencies)
USE_SYSTEM_DEPENDENCIES=true
shift
;;
--help)
MOLECULE_CMD='wrapper-help'
break
;;
wrapper-*)
MOLECULE_CMD="$1"
shift
;;
check|converge|create|dependency|destroy|idempotence|init|lint|list|login|matrix|prepare|side-effect|syntax|test|verify)
if [[ "$MOLECULE_CMD" != '' ]]; then
shift
else
MOLECULE_CMD="$1"
shift
for arg in "$@"; do
POST_ARGS+=("$arg")
done
break
fi
;;
*)
PRE_ARGS+=("$1")
shift
;;
esac
done
set -e
}
detemine_versions() {
if [[ $USE_SYSTEM_DEPENDENCIES == false ]]; then
USE_SYSTEM_DEPENDENCIES="$MOLECULEW_USE_SYSTEM"
fi
if [[ $PYTHON_VERSION == '' ]]; then
PYTHON_VERSION="$MOLECULEW_PYTHON"
fi
if [[ $ANSIBLE_VERSION == '' ]]; then
ANSIBLE_VERSION="$MOLECULEW_ANSIBLE"
fi
if [[ $DOCKER_LIB_VERSION == '' ]]; then
DOCKER_LIB_VERSION="$MOLECULEW_DOCKER_LIB"
fi
if [[ $MOLECULE_VERSION == '' ]]; then
MOLECULE_VERSION="$MOLECULEW_MOLECULE"
fi
if [[ $USE_SYSTEM_DEPENDENCIES == true ]]; then
if [[ $PYTHON_VERSION != '' ]]; then
echo "Error: --python and --use-system-dependencies cannot be used together" >&2
exit 1
fi
PYTHON_VERSION=system
elif [[ $PYTHON_VERSION == '' ]] || [[ $PYTHON_VERSION == 'default' ]]; then
if [[ -f $PYTHON_VERSION_FILE ]]; then
PYTHON_VERSION=$(<"$PYTHON_VERSION_FILE")
fi
if [[ $PYTHON_VERSION == '' ]]; then
query_latest_python_version2
fi
elif [[ $PYTHON_VERSION == 'latest' ]] || [[ $PYTHON_VERSION == 'latest2' ]]; then
query_latest_python_version2
elif [[ $PYTHON_VERSION == 'latest3' ]]; then
query_latest_python_version3
fi
if [[ $ANSIBLE_VERSION == '' ]] || [[ $ANSIBLE_VERSION == 'default' ]]; then
if [[ -f $ANSIBLE_VERSION_FILE ]]; then
ANSIBLE_VERSION=$(<"$ANSIBLE_VERSION_FILE")
fi
if [[ $ANSIBLE_VERSION == '' ]]; then
query_latest_package_version ANSIBLE_VERSION ansible
fi
elif [[ $ANSIBLE_VERSION == 'latest' ]]; then
query_latest_package_version ANSIBLE_VERSION ansible
fi
if [[ $DOCKER_LIB_VERSION == '' ]] || [[ $DOCKER_LIB_VERSION == 'default' ]]; then
if [[ -f $DOCKER_LIB_VERSION_FILE ]]; then
DOCKER_LIB_VERSION=$(<"$DOCKER_LIB_VERSION_FILE")
fi
if [[ $DOCKER_LIB_VERSION == '' ]]; then
query_latest_package_version DOCKER_LIB_VERSION docker
fi
elif [[ $DOCKER_LIB_VERSION == 'latest' ]]; then
query_latest_package_version DOCKER_LIB_VERSION docker
fi
if [[ $MOLECULE_VERSION == '' ]] || [[ $MOLECULE_VERSION == 'default' ]]; then
if [[ -f $MOLECULE_VERSION_FILE ]]; then
MOLECULE_VERSION=$(<$MOLECULE_VERSION_FILE)
fi
if [[ $MOLECULE_VERSION == '' ]]; then
query_latest_package_version MOLECULE_VERSION molecule
fi
elif [[ $MOLECULE_VERSION == 'latest' ]]; then
query_latest_package_version MOLECULE_VERSION molecule
fi
}
activate_virtualenv() {
detemine_versions
MOLECULE_WRAPPER_ENV="$HOME/.moleculew/molecule/$MOLECULE_VERSION/ansible/$ANSIBLE_VERSION/python/$PYTHON_VERSION/docker/$DOCKER_LIB_VERSION"
if [ ! -d "$MOLECULE_WRAPPER_ENV" ]; then
build_dependencies_present
docker_present
python_present
virtualenv_presant
banner "Initializing virtualenv $MOLECULE_WRAPPER_ENV"
virtualenv "--python=$PYTHON_EXE" "$MOLECULE_WRAPPER_ENV"
# shellcheck disable=SC1090
source "$MOLECULE_WRAPPER_ENV/bin/activate"
echo ''
install_ansible
install_docker_lib
install_molecule
else
# shellcheck disable=SC1090
source "$MOLECULE_WRAPPER_ENV/bin/activate"
fi
}
parse_args "$@"
case $MOLECULE_CMD in
wrapper-clean)
wrapper_clean
;;
wrapper-freeze)
wrapper_freeze
;;
wrapper-help)
wrapper_help
;;
wrapper-install)
activate_virtualenv
;;
wrapper-options-ansible)
wrapper_options_ansible
;;
wrapper-options-docker-lib)
wrapper_options_docker_lib
;;
wrapper-options-molecule)
wrapper_options_molecule
;;
wrapper-options-python)
wrapper_options_python
;;
wrapper-options-scenario)
wrapper_options_scenario
;;
wrapper-unfreeze)
wrapper_unfreeze
;;
wrapper-upgrade)
wrapper_upgrade
;;
wrapper-upgrade-versions)
wrapper_upgrade_versions
;;
wrapper-version)
wrapper_version
;;
wrapper-versions)
wrapper_versions
;;
wrapper-virtualenv)
wrapper_virtualenv
;;
wrapper-*)
echo "Unsupported command: $1" >&2
exit 1
;;
*)
activate_virtualenv
# shellcheck disable=SC2086
exec molecule "${PRE_ARGS[@]}" $MOLECULE_CMD "${POST_ARGS[@]}"
;;
esac

View File

@ -0,0 +1,27 @@
---
# This is for the boot console only (i.e. not xterm, ssh or docker).
# The oh-my-zsh prompt appears corrupted unless the console is in UTF-8.
# If the console-setup file is missing don't create it... assume we're
# running in an environment without a boot console (e.g. docker).
- name: check if console-setup exists
stat:
path: /etc/default/console-setup
register: console_setup_file
- name: install console-setup
become: yes
apt:
name: console-setup
state: present
when: console_setup_file.stat.exists
- name: edit console-setup to utf-8
become: yes
lineinfile:
dest: /etc/default/console-setup
regexp: ^CHARMAP=
line: CHARMAP="UTF-8"
state: present
when: console_setup_file.stat.exists
notify:
- dpkg-reconfigure console-setup

View File

@ -0,0 +1,72 @@
---
- name: install dependencies
package:
name: '{{ item }}'
state: present
with_items:
- git
- zsh
- name: clone oh-my-zsh for users
tags:
# Suppress warning: [ANSIBLE0006] git used in place of git module
# Git module doesn't allow us to set `core.autocrlf=input`.
- skip_ansible_lint
become: yes
become_user: '{{ item.username }}'
# core.autocrlf=input prevents https://github.com/robbyrussell/oh-my-zsh/issues/4402
command: 'git clone -c core.autocrlf=input --depth=1 https://github.com/robbyrussell/oh-my-zsh.git .oh-my-zsh'
args:
chdir: '~{{ item.username }}'
creates: '~{{ item.username }}/.oh-my-zsh'
with_items: '{{ users }}'
- name: retrieve powerlevel9k theme from repo
become: yes
become_user: '{{ item.username }}'
git:
repo: 'https://github.com/bhilburn/powerlevel9k.git'
dest: '~{{ item.username }}/.oh-my-zsh/custom/themes/powerlevel9k'
with_items: '{{ users }}'
- name: retrieve powerline fonts
become: yes
become: '{{ item.username }}'
git:
repo: 'https://github.com/ryanoasis/nerd-fonts.git'
dest: '~{{ item.username }}/.fonts'
with_items: '{{ users }}'
- name: install powerline fonts
become: yes
become: '{{ item.username }}'
command: '~{{ item.username }}/.fonts/install.sh'
with_items: '{{ users }}'
- name: set permissions of oh-my-zsh for users
become: yes
file:
path: '~{{ item.username }}/.oh-my-zsh'
# Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability).
mode: 'go-w'
recurse: yes
with_items: '{{ users }}'
- name: set default shell for users
become: yes
user:
name: '{{ item.username }}'
shell: /bin/zsh
with_items: '{{ users }}'
- name: write .zshrc for users
become: yes
become_user: '{{ item.username }}'
template:
src: zshrc.j2
dest: '~{{ item.username }}/.zshrc'
backup: yes
mode: 'u=rw,go=r'
with_items: '{{ users }}'

View File

@ -0,0 +1,6 @@
---
- import_tasks: install.yml
- name: console setup for Debian family distributions
include_tasks: debian-console-setup.yml
when: ansible_os_family == 'Debian'

View File

@ -0,0 +1,109 @@
{{ ansible_managed | comment }}
{% set oh_my_zsh = item.oh_my_zsh|default({}) %}
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="powerlevel9k/powerlevel9k"
# Powerlevel 9k Configurartion
POWERLEVEL9K_MODE='nerdfont-complete'
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=({{ oh_my_zsh.plugins | default(oh_my_zsh_plugins) | join(' ') }})
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
source $HOME/pyenv/.pyenvrc
source $HOME/.aliases

View File

@ -0,0 +1,2 @@
---
# vars file for oh-my-zsh