Commit cbde93fd authored by Dmitriy Safronov's avatar Dmitriy Safronov
Browse files

new

parent 745dec34
Loading
Loading
Loading
Loading
+27 −18
Original line number Diff line number Diff line
@@ -27,13 +27,7 @@ stages:
.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

##########################################################################################################

@@ -48,15 +42,10 @@ check:
  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}"
    - echo "Checking inventory"
    - ansible-inventory -i inventory.ini --graph
    - ansible -i inventory.ini -m ping all

##########################################################################################################

@@ -76,7 +65,27 @@ 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 ${PARAMETERS} -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini"
    - sh run.sh ${PARAMETERS} -u ${USERNAME:-maintenance} -i "${INVENTORY_DIRECTORY}/inventory.ini" "${PLAYBOOK:-deploy.yml}"
    - 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
    - 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
    - |
      if [ -s ansible.cfg ]; then
        export ANSIBLE_CONFIG=ansible.cfg
      fi

      if [ -s run.sh ]; then
        if [ -s setup.sh ]; then
          sh setup.sh
        fi
        sh run.sh
      elif [ -s 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