2021-06-20 20:26:09 -05:00
|
|
|
image: ubuntu:focal
|
|
|
|
stages:
|
2021-07-31 20:03:38 -05:00
|
|
|
- lint
|
2021-06-20 20:26:09 -05:00
|
|
|
- test
|
|
|
|
- play
|
|
|
|
before_script:
|
|
|
|
# Get the packages we need
|
|
|
|
- apt-get update
|
2021-08-01 12:50:59 -05:00
|
|
|
- apt-get install gnupg openssh-client python3-cryptography python3-docker python3-pip python-is-python3 wget -y
|
2021-08-08 00:30:41 -05:00
|
|
|
- pip install ansible ansible-lint pynetbox
|
2021-06-20 20:26:09 -05:00
|
|
|
# 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
|
2021-08-26 03:39:45 -05:00
|
|
|
# Dump the Netbox key
|
|
|
|
- touch private.pem
|
|
|
|
- chmod 0600 private.pem
|
|
|
|
- echo "$NETBOX_USER_KEY" > private.pem
|
2021-06-20 20:26:09 -05:00
|
|
|
# Fix perms on the playbook root
|
|
|
|
- chmod -R 0750 .
|
2021-07-31 20:30:16 -05:00
|
|
|
# Join the Zerotier management network
|
2021-07-31 20:34:09 -05:00
|
|
|
- |
|
|
|
|
[ -n "$ZEROTIER_NETWORK_ID" ] && \
|
2021-07-31 20:30:16 -05:00
|
|
|
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 && \
|
2021-08-01 12:41:46 -05:00
|
|
|
apt-get update && \
|
|
|
|
apt-get install zerotier-one -y && \
|
2021-07-31 20:30:16 -05:00
|
|
|
service zerotier-one start && \
|
2021-07-31 20:46:58 -05:00
|
|
|
sleep 5 && \
|
2021-07-31 20:30:16 -05:00
|
|
|
zerotier-cli join "$ZEROTIER_NETWORK_ID" && \
|
2021-07-31 20:46:58 -05:00
|
|
|
sleep 5 && \
|
2021-07-31 20:30:16 -05:00
|
|
|
zerotier-cli info && \
|
|
|
|
zerotier-cli listnetworks
|
2021-06-20 20:26:09 -05:00
|
|
|
# Get ready for execution
|
2021-08-01 21:39:36 -05:00
|
|
|
- ansible-galaxy install -r requirements.yml
|
2021-07-31 20:30:16 -05:00
|
|
|
after_script:
|
2021-07-31 20:34:09 -05:00
|
|
|
- |
|
|
|
|
[ -n "$ZEROTIER_NETWORK_ID" ] && \
|
2021-07-31 20:30:16 -05:00
|
|
|
zerotier-cli leave "$ZEROTIER_NETWORK_ID"
|
2021-06-20 20:26:09 -05:00
|
|
|
|
|
|
|
Lint:
|
2021-08-01 14:55:25 -05:00
|
|
|
stage: lint
|
2021-06-20 20:26:09 -05:00
|
|
|
allow_failure: yes
|
2021-07-31 21:04:25 -05:00
|
|
|
interruptible: yes
|
2021-08-01 14:55:25 -05:00
|
|
|
except:
|
|
|
|
- pipelines
|
2021-08-01 14:56:59 -05:00
|
|
|
- schedules
|
2021-06-20 20:26:09 -05:00
|
|
|
script:
|
|
|
|
- ansible-lint --version
|
|
|
|
- ansible-lint site.yml
|
|
|
|
|
2021-08-05 11:50:08 -05:00
|
|
|
Test:
|
2021-06-20 20:26:09 -05:00
|
|
|
stage: test
|
2021-08-01 14:55:25 -05:00
|
|
|
interruptible: yes
|
|
|
|
except:
|
|
|
|
- pipelines
|
2021-06-20 20:26:09 -05:00
|
|
|
script:
|
2021-08-05 11:50:08 -05:00
|
|
|
- ansible-playbook --skip-tags no-test -C site.yml --vault-password-file /vaultpw || error="$?"
|
|
|
|
- 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
|
2021-06-20 20:26:09 -05:00
|
|
|
|
2021-09-13 13:50:22 -05:00
|
|
|
Play_Against_Pis:
|
2021-06-20 20:26:09 -05:00
|
|
|
stage: play
|
|
|
|
script:
|
2021-09-13 13:50:22 -05:00
|
|
|
- ansible-playbook -l manufacturers_raspi site.yml --vault-password-file /vaultpw || error="$?"
|
2021-08-05 11:50:08 -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
|
2021-07-31 19:49:14 -05:00
|
|
|
script:
|
2021-08-23 20:05:27 -05:00
|
|
|
- ansible-playbook -l device_roles_workstation site.yml --vault-password-file /vaultpw || error="$?"
|
2021-08-05 11:50:08 -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
|
2021-07-31 19:49:14 -05:00
|
|
|
script:
|
2021-08-05 11:50:08 -05:00
|
|
|
- ansible-playbook -l tags_prod site.yml --vault-password-file /vaultpw || error="$?"
|
|
|
|
- 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
|