Skip to content
Snippets Groups Projects
Commit 9f4031b2 authored by Engin Yöyen's avatar Engin Yöyen
Browse files

Trigger role updates via bash file

parent abb6d54c
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ If infrastructures are to be treated as a code than projects that manage them mu
* Staging
* Complexity of plays
* Encryption of data(e.g. passwords, certificates)
* Installation of ansible and module dependencies
##TL;DR
* Do not keep external roles in your repository, use ansible-galaxy
......@@ -19,6 +20,7 @@ If infrastructures are to be treated as a code than projects that manage them mu
* Different environments(development,test,production) must be close as possible, if not equal
* Do not put your password or certificates as plain text in your git repo, use ansible-vault for encrypting
* Use tags in your play
* Keep all your ansible dependencies in a single place and make the installation dead-simple
##1. Directory Layout
......@@ -61,13 +63,12 @@ It is a bad habit to keep the copy of roles, that are developed by other develop
---
- src: ANXS.build-essential
version: "v1.0.1"
path : external
```
Roles can be downloaded with this command:
```
ansible-galaxy install -r roles_requirements.yml
./extensions/setup/role_update.sh
```
......@@ -108,13 +109,31 @@ It is most likely that you will have a password or certificates in your reposito
To decrypt the file, you need the vault password, which you can place in your root directory but it MUST NOT be committed to your git repository. You should share the password with you coworkers with some other method than committing to git a repo.
##8. Project Setup
As it should be very easy to set-up the work environment, all required packages that ansible needs, as well as ansible should be installed very easily. This will allow newcomers or developers to start using ansible project very fast and easy. Therefore, python_requirements.txt file is located at:
```
extensions/setup/python_requirements.txt
```
This structure will help you to keep your dependencies in a single place, as well as making it easier to install everything including ansible. All you have to do is to execute the setup file:
```
./extensions/setup/setup.sh
```
#Running the Code
Code in this repo is functional and test it. To run it:
Code in this repo is functional and test it. To run it, you need to install ansible and all the dependencies. You can do this simply by executing:
```
./extensions/setup/setup.sh
```
* Create a vpass text file in the root directory and add the secret code (123456)
* Go to roles directory and execute to download roles
* If you all ready have ansible, and you do not want to go throught the installation simply create a vpass text file in the root directory and add the secret code (123456)
* To install roles execure the role_update.sh which will download all the roles
```
ansible-galaxy install -r roles_requirements.yml --force
./extensions/setup/role_update.sh
```
* Go to plays directory and the execute and do not forget to change the host address in the development.ini
```
......
#!/bin/bash
set -e
#TODO: Support python virtual environments for now global
COLOR_END='\e[0m'
COLOR_RED='\e[0;31m'
# This current directory.
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
ROOT_DIR=$(cd "$DIR/../../" && pwd)
EXTERNAL_ROLE_DIR="$ROOT_DIR/roles/external"
ROLES_REQUIREMNTS_FILE="$ROOT_DIR/roles/roles_requirements.yml"
# Exit msg
msg_exit() {
printf "$COLOR_RED$@$COLOR_END"
printf "\n"
printf "Exiting...\n"
exit 1
}
# Trap if ansible-galaxy failed and warn user
cleanup() {
msg_exit "Update failed. Please don't commit or push roles till you fix the issue"
}
trap "cleanup" ERR INT TERM
# Check ansible-galaxy
[[ -z "$(which ansible-galaxy)" ]] && msg_exit "Ansible is not installed or not in your path."
# Check roles req file
[[ ! -f "$ROLES_REQUIREMNTS_FILE" ]] && msg_exit "roles_requirements '$ROLES_REQUIREMNTS_FILE' does not exist or permssion issue.\nPlease check and rerun."
# Remove existing roles
if [ -d "$EXTERNAL_ROLE_DIR" ]; then
cd "$EXTERNAL_ROLE_DIR"
if [ "$(pwd)" == "$EXTERNAL_ROLE_DIR" ];then
echo "Removing current roles in '$EXTERNAL_ROLE_DIR/*'"
rm -rf *
else
msg_exit "Path error could not change dir to $EXTERNAL_ROLE_DIR"
fi
fi
# Install roles
ansible-galaxy install -r "$ROLES_REQUIREMNTS_FILE" --force --no-deps -p "$EXTERNAL_ROLE_DIR"
exit 0
- src: git+https://github.com/yetu/ansible-apt.git
version: "v0.1.4"
name: ansible-apt
path : external
- src: git+https://github.com/yetu/ansible-hostname.git
version: "v0.1.2"
name: ansible-hostname
path : external
- src: git+https://github.com/Stouts/Stouts.sudo.git
version: "1.0.0"
path : external
- src: git+https://github.com/ANXS/openssh.git
version: "v1.0.1"
name: ANXS.openssh
path : external
- src: git+https://github.com/knopki/ansible-locale.git
version: "v1.0.3"
name: knopki.locale
path : external
- src: git+https://github.com/ANXS/postgresql.git
version: "v1.1.1"
name: ANXS.postgresql
path : external
- src: git+https://github.com/yetu/ansible-nginx.git
#version: "v1.0.1"
- src: git+https://github.com/AutomationWithAnsible/ansible-nginx.git
version: "v1.0.3"
name: ansible-nginx
path : external
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment