Newer
Older
# VARIABLES
variables:
DOCKER_BUILDKIT: 1
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://localhost:2375
DOCKER_TLS_CERTDIR: ""
GIT_URL:
value: ""
description: "ОБЯЗАТЕЛЬНАЯ ПЕРЕМЕННАЯ: http(s) адрес репозитория системной конфигурации"
GIT_LOGIN:
value: ""
description: "НЕобязательная переменная: логин репозитория системной конфигурации"
GIT_PASSWORD:
value: ""
description: "НЕобязательная переменная: пароль репозитория системной конфигурации"
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
##########################################################################################################
## PIPELINE DEFINITION
stages:
- check
- deploy
##########################################################################################################
### COMMON SECTION
.common: &common
image: registry.cyberbrain.pw/ansible/ansible
before_script:
- eval $(ssh-agent -s); echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- chmod -R o-w ../
- export INVENTORY_DIRECTORY="`pwd`"
- mkdir -p /tmp/checkout
- git config --global credential.helper store
- echo "https://${GIT_LOGIN}:${GIT_PASSWORD}@$(echo ${GIT_URL} | sed -r 's#([^/])/[^/].*#\1#' | sed -e 's|https://||g')" > ~/.git-credentials
##########################################################################################################
### CHECK SECTION
check:
<<: *common
stage: check
variables:
GIT_DEPTH: 1
ANSIBLE_FORCE_COLOR: "True"
ANSIBLE_HOST_KEY_CHECKING: "False"
only:
refs:
- trunk
variables:
- $GIT_URL =~ /^\S+$/
script:
- echo "Checking configuration [${GIT_URL}] with parameters [${PARAMETERS}]"
- git clone "${GIT_URL}" /tmp/checkout
- cd /tmp/checkout
- ls -la
- sh setup.sh ${PARAMETERS} --check -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini"
- sh run.sh ${PARAMETERS} --check -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini" "${PLAYBOOK:-deploy.yml}"
##########################################################################################################
### DEPLOY SECTION
deploy:
<<: *common
stage: deploy
variables:
GIT_DEPTH: 1
ANSIBLE_FORCE_COLOR: "True"
ANSIBLE_HOST_KEY_CHECKING: "False"
ANSIBLE_STDOUT_CALLBACK: "actionable"
only:
refs:
- master
variables:
- $GIT_URL =~ /^\S+$/
script:
- echo "Deploying configuration [${GIT_URL}] with parameters [${PARAMETERS}]"
- git clone "${GIT_URL}" /tmp/checkout
- cd /tmp/checkout
- sh setup.sh ${PARAMETERS} -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini"
- sh run.sh ${PARAMETERS} -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini" "${PLAYBOOK:-deploy.yml}"