ansible/.gitlab-ci.yml

90 lines
3.1 KiB
YAML
Raw Normal View History

image: rehashedsalt/ansible-env:bleeding
variables:
ANSIBLE_INVENTORY: inventories/production-no-auto
ANSIBLE_STRATEGY: free
stages:
- lint
- test
2022-03-07 10:46:02 -06:00
- play-pre
- play-main
- play-post
before_script:
# 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 ~/.vault_pass
- chmod 0600 ~/.vault_pass
- echo "$ANSIBLE_VAULT_PASSWORD" > ~/.vault_pass
# 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" ] && \
service zerotier-one start && \
sleep 5 && \
zerotier-cli join "$ZEROTIER_NETWORK_ID" && \
sleep 5 && \
zerotier-cli info && \
zerotier-cli listnetworks
# Get ready for execution
2021-08-01 21:39:36 -05:00
- ansible-galaxy install -r requirements.yml
# Run a quick test SSH connection to the bastion box
- ssh -o StrictHostKeyChecking=no ansible@bastion1.dallas.mgmt.desu.ltd uptime
# And a quick test SSH connection over proxy
- ssh -o StrictHostKeyChecking=no -o ProxyCommand="ssh -W %h:%p -q ansible@bastion1.dallas.mgmt.desu.ltd" ansible@bastion1.dallas.mgmt.desu.ltd uptime
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
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
2023-03-20 20:54:36 -05:00
- ansible-lint site.yml --offline
Test:
stage: test
retry: 1
2021-08-01 14:55:25 -05:00
interruptible: yes
except:
- pipelines
script:
- ansible-playbook --skip-tags no-test,no-auto -C site.yml --ssh-common-args='-o ProxyCommand="ssh -W %h:%p -q ansible@bastion1.dallas.mgmt.desu.ltd"' --vault-password-file ~/.vault_pass || 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
2022-03-07 10:46:02 -06:00
# PRE-MAIN CONFIGURATION
Local:
stage: play-pre
script:
- ansible-playbook --skip-tags no-auto playbooks/site_local.yml --ssh-common-args='-o ProxyCommand="ssh -W %h:%p -q ansible@bastion1.dallas.mgmt.desu.ltd"' --vault-password-file ~/.vault_pass
2022-03-07 10:46:02 -06:00
Pre:
stage: play-pre
script:
- ansible-playbook --skip-tags no-auto playbooks/site_pre.yml --ssh-common-args='-o ProxyCommand="ssh -W %h:%p -q ansible@bastion1.dallas.mgmt.desu.ltd"' --vault-password-file ~/.vault_pass
2022-03-07 10:46:02 -06:00
# MAIN CONFIGURATION
Main:
stage: play-main
2022-10-21 08:29:18 -05:00
retry: 1
2022-03-07 10:46:02 -06:00
script:
- ansible-playbook --skip-tags no-auto playbooks/site_main.yml --ssh-common-args='-o ProxyCommand="ssh -W %h:%p -q ansible@bastion1.dallas.mgmt.desu.ltd"' --vault-password-file ~/.vault_pass
2022-03-07 10:46:02 -06:00
Common:
stage: play-main
script:
- ansible-playbook --skip-tags no-auto playbooks/site_common.yml --ssh-common-args='-o ProxyCommand="ssh -W %h:%p -q ansible@bastion1.dallas.mgmt.desu.ltd"' --vault-password-file ~/.vault_pass
2022-03-07 10:46:02 -06:00
# CLEANUP
Cleanup:
stage: play-post
script:
- ansible-playbook --skip-tags no-auto playbooks/site_post.yml --ssh-common-args='-o ProxyCommand="ssh -W %h:%p -q ansible@bastion1.dallas.mgmt.desu.ltd"' --vault-password-file ~/.vault_pass