feat(automation): job to run ansible playbooks

!29 nofusscomputing/projects/ansible/execution_environment!8 nofusscomputing/projects/ansible-roles!25 nofusscomputing/projects/ansible/git_configuration#5
This commit is contained in:
2023-05-26 16:29:23 +09:30
parent 0a17fe1aa3
commit 0d3eaa6ac2

View File

@ -0,0 +1,60 @@
---
# This yaml is intended to automagically create automation jobs if included
include:
- local: $JOB_ROOT_DIR/.gitlab-ci_common.yaml
.ansible_playbook:
image: nofusscomputing/ansible-ee:dev
stage: chores
variables:
ansible_inventory: ''
ansible_playbook: ''
ansible_tags: ''
# uncomment below when there is a playbook done
#ANSIBLE_PLAYBOOK_DIR: '/etc/ansible/playbooks' only use for role in the ansible-ee container
script:
- if [ "0$ansible_inventory" != '0' ]; then ansible_inventory=-i $ansible_inventory; fi
- if [ "0$ansible_tags" != '0' ]; then ansible_tags=$(echo -n "--tags $ansible_tags"); fi
- echo "[DEBUG] ansible_inventory=$ansible_inventory"
- echo "[DEBUG] ansible_playbook=$ansible_playbook"
- echo "[DEBUG] ansible_tags=$ansible_tags"
# remove galaxy and pip commands when the ansible-ee image is fixed
- ansible-galaxy collection install community.general
- pip install python_gitlab==3.14.0
- ansible-playbook $ansible_inventory $ansible_playbook $ansible_tags -vvv --extra-vars repo_root=$CI_PROJECT_DIR
rules:
# test rules with default never and to specify only when
# - if: '$CI_COMMIT_TAG'
# when: never
# - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
# when: never
- if: ' $NFC_AUTO_JOBS == "false"'
when: never
- if: '$CI_PIPELINE_SOURCE == "schedule" && $PIPELINE_RUN_SCHEDULE == "true"'
exists:
- ".nfc_automation.yaml"
when: always
- if: '$CI_PIPELINE_SOURCE == "pipeline" && $PIPELINE_RUN_TRIGGER == "true"'
exists:
- ".nfc_automation.yaml"
when: always
# this if for testing only
# - if: '$CI_PIPELINE_SOURCE == "push"'
# when: always
# exists:
# - ".nfc_automation.yaml"
- when: never
Update Git Submodules:
extends: .ansible_playbook
variables:
ansible_playbook: '.nfc_automation.yaml'
ansible_tags: 'submodule'
PIPELINE_RUN_TRIGGER: 'false'
PIPELINE_RUN_SCHEDULE: 'false'