Skip to content
Snippets Groups Projects
Verified Commit b71bda53 authored by Varac's avatar Varac
Browse files

Use ansible-playbook for CI

Closes: #42
parent 56349891
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 files created by ansible-playbook
*.retry
# Ignore generated files during CI
/test/artifacts/
/test/inventory
/test/env/extravars
# Ignore files created during CI using test/ci-bootstrap.py
/test/group_vars/
/test/inventory.yml
# Etc
__pycache__
*.log
......@@ -22,13 +22,15 @@ bootstrap:
script:
- apk update
- apk add ansible musl-dev linux-headers gcc py3-psutil openssh-client moreutils
- pip3 install ansible-runner requests tabulate
- cd test
- 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 | ts
artifacts:
paths:
- ansible/rke.log
......
../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