Skip to content
Snippets Groups Projects
Commit 6c478e93 authored by Arie Peterson's avatar Arie Peterson
Browse files

Merge branch '42_ansible_playbook' into 'master'

42 ansible playbook

Closes #36, #43, and #42

See merge request openappstack/bootstrap!24
parents 3aad6202 27bfda29
No related branches found
No related tags found
No related merge requests found
# Ignore custom files created when following the README.md
/ansible/group_vars/cluster/settings.yml
/ansible/inventory.yml
# Ignore generated files during CI
/test/artifacts/
/test/inventory
/test/env/extravars
# Ignore files created by ansible-playbook
*.retry
# Ignore files created during CI using test/ci-bootstrap.py
/test/group_vars/
/test/inventory.yml
# Etc
__pycache__
*.log
......@@ -18,17 +18,19 @@ control_image:
bootstrap:
stage: deploy
image: alpine:edge
image: alpine
script:
- apk update
- apk add ansible musl-dev linux-headers gcc py3-psutil openssh-client moreutils
- pip3 install ansible-runner requests tabulate
- cd test
- apk add ansible musl-dev linux-headers gcc py3-psutil openssh-client
- pip3 install requests tabulate
# Ensure test/ is not world-writable otherwise ansible-playbook refuses to run, see
# https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir
- chmod 755 test/
- cd test/
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p --mode 700 ~/.ssh
- date
- python3 -u ./ci-bootstrap.py --create_droplet --terminate | ts
# - mkdir -p --mode 700 ~/.ssh
- ANSIBLE_HOST_KEY_CHECKING=False python3 -u ./ci-bootstrap.py --create_droplet --terminate
artifacts:
paths:
- ansible/rke.log
......
......@@ -26,7 +26,7 @@ Also copy `ansible/group_vars/cluster/settings.yml.example` to
To run the bootstrap process, move into the `ansible` directory, then run
```
ansible-playbook -i inventory.yml bootstrap.yml
ansible-playbook bootstrap.yml
```
## Managing an existing cluster
......
[defaults]
callback_whitelist = profile_tasks, timer
inventory = inventory.yml
nocows = 1
stdout_callback = yaml
../ansible/ansible.cfg
\ No newline at end of file
......@@ -20,13 +20,14 @@ In Debian:
pip3 install ansible-runner requests tabulate
"""
import ansible_runner
import argparse
import cosmos
import logging
import os
import random
import shlex
import string
import subprocess
import sys
import traceback
import yaml
......@@ -165,7 +166,7 @@ if __name__ == "__main__":
inventory['all']['children']['master']['hosts'] = name
inventory['all']['children']['worker']['hosts'] = name
with open('./inventory', 'w') as stream:
with open('./inventory.yml', 'w') as stream:
yaml.dump(inventory, stream, default_flow_style=False)
# Create settings
......@@ -177,9 +178,9 @@ if __name__ == "__main__":
settings['domain'] = name + '.ci.openappstack.net'
settings['admin_email'] = "admin@{0}".format(settings['domain'])
if not os.path.exists('./env'):
os.mkdir('./env')
with open('./env/extravars', 'w') as stream:
if not os.path.exists('./group_vars'):
os.mkdir('./group_vars')
with open('./group_vars/all', 'w') as stream:
yaml.dump(settings, stream, default_flow_style=False)
log.debug(yaml.dump(inventory, default_flow_style=False))
......@@ -188,23 +189,20 @@ if __name__ == "__main__":
# Bootstrap
# playbook path here is relative to private_data_dir/project, see
# https://ansible-runner.readthedocs.io/en/latest/intro.html#inputdir
ansible_run = ansible_runner.run(
private_data_dir='.',
playbook='../../ansible/bootstrap.yml')
log.info('ansible_run.rc: %s', ansible_run.rc)
log.info('ansible_run.status: %s\n', ansible_run.status)
log.debug('ansible_run.stats: %s', ansible_run.stats)
for each_host_event in ansible_run.events:
log.debug('ansible_run.events.each_host_event["event"]: %s',
each_host_event['event'])
if ansible_run.rc > 0:
playbook='../ansible/bootstrap.yml'
ansible_playbook_cmd = 'ansible-playbook %s' % playbook
log.info('Running %s', ansible_playbook_cmd)
result = subprocess.run(shlex.split(ansible_playbook_cmd))
if result.returncode > 0:
try:
raise RuntimeError('ansible-runner failed.')
raise RuntimeError('Playbook failed with rc %s.'
% result.returncode)
except RuntimeError:
traceback.print_exc()
sys.exit(ansible_run.rc)
sys.exit(result.returncode)
if args.terminate:
cosmos.terminate_droplet(id)
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