ansible/.gitlab-ci.yml

82 lines
2.7 KiB
YAML
Raw Normal View History

image: ubuntu:focal
stages:
- lint
- test
- play
before_script:
# Get the packages we need
- apt-get update
- apt-get install gnupg openssh-client python3-cryptography python3-docker python3-pip python-is-python3 wget -y
- pip install ansible ansible-lint
# Dump our key
- eval $(ssh-agent -s)
- echo "$ANSIBLE_SSH_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod -R 0700 ~/.ssh
# Dump the vault password
- touch /vaultpw
- chmod 0600 /vaultpw
- echo "$ANSIBLE_VAULT_PASSWORD" > /vaultpw
# Fix perms on the playbook root
- chmod -R 0750 .
# Join the Zerotier management network
2021-07-31 20:34:09 -05:00
- |
[ -n "$ZEROTIER_NETWORK_ID" ] && \
wget -qO - https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg | apt-key add - && \
echo "deb http://download.zerotier.com/debian/buster buster main" >> /etc/apt/sources.list && \
apt-get update && \
apt-get install zerotier-one -y && \
service zerotier-one start && \
sleep 5 && \
zerotier-cli join "$ZEROTIER_NETWORK_ID" && \
sleep 5 && \
zerotier-cli info && \
zerotier-cli listnetworks
# Get ready for execution
- ansible-galaxy install -r roles/requirements.yml -p roles
after_script:
2021-07-31 20:34:09 -05:00
- |
[ -n "$ZEROTIER_NETWORK_ID" ] && \
zerotier-cli leave "$ZEROTIER_NETWORK_ID"
Lint:
2021-08-01 14:55:25 -05:00
stage: lint
allow_failure: yes
interruptible: yes
2021-08-01 14:55:25 -05:00
except:
- pipelines
2021-08-01 14:56:59 -05:00
- schedules
script:
- ansible-lint --version
- ansible-lint site.yml
Test:
stage: test
2021-08-01 14:55:25 -05:00
interruptible: yes
except:
- pipelines
2021-08-01 14:56:59 -05:00
- schedules
script:
2021-08-01 13:32:26 -05:00
- ansible-playbook --skip-tags no-test -C site.yml --vault-password-file /vaultpw || error="$?"
2021-08-01 13:38:23 -05:00
- if [ "$error" -eq 4 ]; then echo "Some hosts were unreachable; masking error"; unset error; fi
- if [ -n "$error" ]; then echo "Return code $error"; false; fi
Play_Against_Pis:
stage: play
script:
2021-08-01 13:35:08 -05:00
- ansible-playbook -l pis site.yml --vault-password-file /vaultpw || error="$?"
2021-08-01 13:38:23 -05:00
- if [ "$error" -eq 4 ]; then echo "Some hosts were unreachable; masking error"; unset error; fi
- if [ -n "$error" ]; then echo "Return code $error"; false; fi
Play_Against_Desktops:
stage: play
script:
2021-08-01 13:32:26 -05:00
- ansible-playbook -l desktop site.yml --vault-password-file /vaultpw || error="$?"
2021-08-01 13:38:23 -05:00
- if [ "$error" -eq 4 ]; then echo "Some hosts were unreachable; masking error"; unset error; fi
- if [ -n "$error" ]; then echo "Return code $error"; false; fi
Play_Against_Production:
stage: play
script:
2021-08-01 13:35:08 -05:00
- ansible-playbook -l prod site.yml --vault-password-file /vaultpw || error="$?"
2021-08-01 13:38:23 -05:00
- if [ "$error" -eq 4 ]; then echo "Some hosts were unreachable; masking error"; unset error; fi
- if [ -n "$error" ]; then echo "Return code $error"; false; fi