Commit 0bd7ec53 authored by Clement's avatar Clement Committed by Pierre Smeyers
Browse files

feat: add pre-ansible-galaxy.sh hook

parent c8cddaac
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ To activate environment cleanup, you need to set `ANSIBLE_xxx_CLEANUP_PLAYBOOK_F
Deployment jobs also support _optional_ **hook scripts** from your project, located in the `$ANSIBLE_SCRIPTS_DIR` directory
(root project dir by default, but may be overridden).

* `pre-ansible-galaxy.sh` is executed **before** running `ansible-galaxy install` to perform specific pre-initialization such as configuring custom Galaxy servers or preparing authentication,
* `pre-ansible-playbook.sh` is executed **before** running `ansible-playbook` to perform specific environment pre-initialization such as generating a dynamic inventory,
* `post-ansible-playbook.sh` is executed **after** running `ansible-playbook` to perform specific environment post-initialization.

+12 −1
Original line number Diff line number Diff line
@@ -631,6 +631,16 @@ stages:

  function maybe_install_requirements() {
    configure_netrc
    
    # maybe execute pre ansible-galaxy script
    prescript="$ANSIBLE_SCRIPTS_DIR/pre-ansible-galaxy.sh"
    if [[ -f "$prescript" ]]; then
      log_info "--- \\e[32mpre-ansible-galaxy\\e[0m hook (\\e[33;1m${prescript}\\e[0m) found: execute"
      exec_hook "$prescript"
    else
      log_info "--- \\e[32mpre-ansible-galaxy\\e[0m hook (\\e[33;1m${prescript}\\e[0m) not found: skip"
    fi
    
    if [ -f "$ANSIBLE_REQUIREMENTS_FILE" ]
    then
      log_info "--- \\e[32mrequirements\\e[0m file (\\e[33;1m${ANSIBLE_REQUIREMENTS_FILE}\\e[0m) found: running \\e[33;1mansible-galaxy install\\e[0m"
@@ -670,6 +680,8 @@ stages:
    rm -f ansible.env
    rm -f environment_url.txt

    maybe_install_requirements

    # maybe execute pre ansible-playbook script
    prescript="$ANSIBLE_SCRIPTS_DIR/pre-ansible-playbook.sh"
    if [[ -f "$prescript" ]]; then
@@ -679,7 +691,6 @@ stages:
      log_info "--- \\e[32mpre-ansible-playbook\\e[0m hook (\\e[33;1m${prescript}\\e[0m) not found: skip"
    fi

    maybe_install_requirements

    # extra var environment_type & environment_name
    ansible_opts="-e environment_type=$environment_type -e environment_name=$environment_name"