Loading gitlab-ci.yml +33 −28 Original line number Diff line number Diff line Loading @@ -2,10 +2,11 @@ # VARIABLES variables: DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 0 DOCKER_DRIVER: overlay2 DOCKER_HOST: tcp://localhost:2375 DOCKER_TLS_CERTDIR: "" GIT_DEPTH: 1 ########################################################################################################## Loading @@ -17,50 +18,38 @@ stages: ########################################################################################################## ### COMMON SECTION .common: &common image: registry.cyberbrain.pw/ansible/ansible .common: image: $ANSIBLE_IMAGE variables: GIT_DEPTH: 1 ANSIBLE_FORCE_COLOR: "True" ANSIBLE_HOST_KEY_CHECKING: "False" 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 extends: .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 - sh run.sh ${PARAMETERS} --check -u maintenance -i "${INVENTORY_DIRECTORY}/inventory.ini" ${PLAYBOOK:-deploy.yml} - echo "Checking inventory" - ansible-inventory -i inventory.ini --graph - ansible -i inventory.ini -m ping all -u ${USERNAME:-maintenance} || ( test -n "${CHECK_SKIP_ERRORS}" && true ) ########################################################################################################## ### DEPLOY SECTION deploy: <<: *common extends: .common stage: deploy variables: GIT_DEPTH: 1 ANSIBLE_FORCE_COLOR: "True" ANSIBLE_HOST_KEY_CHECKING: "False" ANSIBLE_STDOUT_CALLBACK: "actionable" only: refs: Loading @@ -69,7 +58,23 @@ deploy: - $GIT_URL =~ /^\S+$/ script: - echo "Deploying configuration [${GIT_URL}] with parameters [${PARAMETERS}]" - git clone "${GIT_URL}" /tmp/checkout - cd /tmp/checkout - sh setup.sh - sh run.sh ${PARAMETERS} -u maintenance -i "${INVENTORY_DIRECTORY}/inventory.ini" ${PLAYBOOK:-deploy.yml} - export INVENTORY_DIRECTORY="`pwd`" - 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 - mkdir -p /tmp/checkout && git clone "${GIT_URL}" /tmp/checkout && cd /tmp/checkout - | export ANSIBLE_CONFIG="${INVENTORY_DIRECTORY}/ansible.cfg" if [ -s ansible.cfg ]; then export ANSIBLE_CONFIG=ansible.cfg fi if [ -s run.sh ]; then sh run.sh elif [ -s "${PLAYBOOK:-deploy.yml}" ]; then if [ -s requirements.yml ]; then ansible-galaxy install -r requirements.yml fi ansible-playbook ${PARAMETERS} -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini" "${PLAYBOOK:-deploy.yml}" else echo "Error - no actions available!" exit 1 fi Loading
gitlab-ci.yml +33 −28 Original line number Diff line number Diff line Loading @@ -2,10 +2,11 @@ # VARIABLES variables: DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 0 DOCKER_DRIVER: overlay2 DOCKER_HOST: tcp://localhost:2375 DOCKER_TLS_CERTDIR: "" GIT_DEPTH: 1 ########################################################################################################## Loading @@ -17,50 +18,38 @@ stages: ########################################################################################################## ### COMMON SECTION .common: &common image: registry.cyberbrain.pw/ansible/ansible .common: image: $ANSIBLE_IMAGE variables: GIT_DEPTH: 1 ANSIBLE_FORCE_COLOR: "True" ANSIBLE_HOST_KEY_CHECKING: "False" 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 extends: .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 - sh run.sh ${PARAMETERS} --check -u maintenance -i "${INVENTORY_DIRECTORY}/inventory.ini" ${PLAYBOOK:-deploy.yml} - echo "Checking inventory" - ansible-inventory -i inventory.ini --graph - ansible -i inventory.ini -m ping all -u ${USERNAME:-maintenance} || ( test -n "${CHECK_SKIP_ERRORS}" && true ) ########################################################################################################## ### DEPLOY SECTION deploy: <<: *common extends: .common stage: deploy variables: GIT_DEPTH: 1 ANSIBLE_FORCE_COLOR: "True" ANSIBLE_HOST_KEY_CHECKING: "False" ANSIBLE_STDOUT_CALLBACK: "actionable" only: refs: Loading @@ -69,7 +58,23 @@ deploy: - $GIT_URL =~ /^\S+$/ script: - echo "Deploying configuration [${GIT_URL}] with parameters [${PARAMETERS}]" - git clone "${GIT_URL}" /tmp/checkout - cd /tmp/checkout - sh setup.sh - sh run.sh ${PARAMETERS} -u maintenance -i "${INVENTORY_DIRECTORY}/inventory.ini" ${PLAYBOOK:-deploy.yml} - export INVENTORY_DIRECTORY="`pwd`" - 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 - mkdir -p /tmp/checkout && git clone "${GIT_URL}" /tmp/checkout && cd /tmp/checkout - | export ANSIBLE_CONFIG="${INVENTORY_DIRECTORY}/ansible.cfg" if [ -s ansible.cfg ]; then export ANSIBLE_CONFIG=ansible.cfg fi if [ -s run.sh ]; then sh run.sh elif [ -s "${PLAYBOOK:-deploy.yml}" ]; then if [ -s requirements.yml ]; then ansible-galaxy install -r requirements.yml fi ansible-playbook ${PARAMETERS} -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini" "${PLAYBOOK:-deploy.yml}" else echo "Error - no actions available!" exit 1 fi