Skip to content

Commit

Permalink
DSOS-2361: additional group vars for sub environments (#447)
Browse files Browse the repository at this point in the history
* Add additional group vars for sub-environemnts, e.g. nomis-environment tag

* Update ansible script to support sub-environments
  • Loading branch information
drobinson-moj authored Dec 13, 2023
1 parent 67bc46d commit 68e0908
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ansible/hosts/autoscaling_group_aws_ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ compose:
keyed_groups:
- key: tags['environment-name']
prefix: environment-name
- key: tags['environment-name'] + '-' + tags[application + '-environment']
prefix: environment-name
- key: tags['ami']
prefix: ami
- key: tags['server-type']
prefix: server-type
- key: tags['server-type'] + '-' + tags[application + '-environment']
prefix: server-type
- key: tags['os-type'] | lower
prefix: os-type

Expand Down
4 changes: 4 additions & 0 deletions ansible/hosts/instance_aws_ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ compose:
keyed_groups:
- key: tags['environment-name']
prefix: environment-name
- key: tags['environment-name'] + '-' + tags[application + '-environment']
prefix: environment-name
- key: tags['ami']
prefix: ami
- key: tags['server-type']
prefix: server-type
- key: tags['server-type'] + '-' + tags[application + '-environment']
prefix: server-type
- key: tags['os-type'] | lower
prefix: os-type
- key: tags['environment-name'] + '_' + tags['delius-environment-name'] + '_all'
Expand Down
14 changes: 14 additions & 0 deletions ansible/roles/ansible-script/files/ansible.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ run_ansible() {
fi
done

echo "# Checking for $application-environment tag using aws cli"
application_environment=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$instance_id" "Name=key,Values=$application-environment" --output=text | head -1 | cut -f5)
if [[ -n $application_environment ]]; then
for ((i=0; i<${#tags[@]}; i++)); do
tag=(${tags[i]})
group=$(echo "${tag[1]}_${tag[4]}_${application_environment}" | tr [:upper:] [:lower:] | sed "s/-/_/g")
if [[ -e $ansible_dir/${ansible_repo}/${ansible_repo_basedir}/group_vars/$group.yml ]]; then
ansible_group_vars="$ansible_group_vars --extra-vars @group_vars/$group.yml"
elif [[ -e $ansible_dir/${ansible_repo}/${ansible_repo_basedir}/group_vars/$group/ansible.yml ]]; then
ansible_group_vars="$ansible_group_vars --extra-vars @group_vars/$group/ansible.yml"
fi
done
fi

# set python version
if [[ $(which python3.9 2> /dev/null) ]]; then
python=$(which python3.9)
Expand Down

0 comments on commit 68e0908

Please sign in to comment.