Skip to content

Commit 104f44a

Browse files
authored
Merge pull request #49 from bitovi/feature/ansible-vars-file
Allow users to pass custom Ansible vars file
2 parents a904c9a + 4ae299d commit 104f44a

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
4646
st2_auth_username: ${{ secrets.ST2_AUTH_USERNAME}}
4747
st2_auth_password: ${{ secrets.ST2_AUTH_PASSWORD}}
48+
st2_packs: "st2,aws,github"
4849
```
4950
5051
This will create the following resources in AWS:
@@ -81,12 +82,12 @@ The following inputs can be used as `steps.with` keys:
8182
| `st2_auth_username` | string | | Username used by StackStorm standalone authentication. Set as a secret in GH Actions. |
8283
| `st2_auth_password` | string | | Password used by StackStorm standalone authentication. Set as a secret in GH Actions. |
8384
| `st2_packs` | string |`"st2"` | Comma separated list of packs to install. If you modify this option, be sure to also include `st2` in the list. |
85+
| `st2_ansible_extra_vars_file` | string | | Relative path from project root to Ansible vars file. If you'd like to adjust more advanced configuration; st2 version, st2.conf, RBAC, chatops, auth, etc. See https://github.com/stackStorm/ansible-st2#variables for the full list of settings. The Ansible vars will take higher precedence over the GHA inputs. |
8486
| **Cleanup** |
8587
| `tf_stack_destroy` | bool | `false` | Set to `true` to Destroy the created AWS infrastructure for this instance |
8688
| `tf_state_bucket_destroy` | bool | `false` | Force purge and deletion of `tf_state_bucket` defined. Any file contained there will be destroyed. `tf_stack_destroy` must also be `true` |
8789

88-
89-
## Note about AWS resource identifiers
90+
### Note about AWS resource identifiers
9091
Most resources will contain the tag `GITHUB_ORG-GITHUB_REPO-GITHUB_BRANCH` to make them unique. Because some AWS resources have a length limit, we shorten identifiers to a `60` characters max string.
9192

9293
We use the Kubernetes style for this. For example, `Kubernetes` -> `k(# of characters)s` -> `k8s`. And so you might see how compressions are made.
@@ -96,6 +97,48 @@ For some specific resources, we have a `32` characters limit. If the identifier
9697
### S3 buckets naming
9798
Bucket names can be made of up to 63 characters. If the length allows us to add `-tf-state`, we will do so. If not, a simple `-tf` will be added.
9899

100+
### Advanced StackStorm configuration with Ansible vars
101+
This action runs [`ansible-st2`](https://github.com/stackStorm/ansible-st2) roles under the hood. You can customize the Ansible configuration by creating a yaml file in your repo. This file will be passed to the Ansible playbook as extra vars. See the [Ansible-st2](https://github.com/stackStorm/ansible-st2#variables) documentation for a full list of available options.
102+
103+
Here is an example `st2_vars.yaml` pinning the stackstorm to `v3.8.0`, installing several packs from [StackStorm Exchange](https://exchange.stackstorm.org) and configuring `st2.conf` with extra settings for `garbagecollector`:
104+
105+
```yaml
106+
st2_version: "3.8.0"
107+
108+
# Install specific pack versions from StackStorm Exchange
109+
st2_packs:
110+
- st2
111+
- aws=1.2.0
112+
- github=2.1.3
113+
114+
# https://github.com/StackStorm/st2/blob/master/conf/st2.conf.sample
115+
st2_config:
116+
garbagecollector:
117+
# Action executions and related objects (live actions, action output objects) older than this value (days) will be automatically deleted. Defaults to None (disabled).
118+
action_executions_ttl = 90
119+
```
120+
121+
Example GHA deployment job referencing the Ansible `st2_vars.yaml` file:
122+
```yaml
123+
jobs:
124+
deploy-st2:
125+
runs-on: ubuntu-latest
126+
steps:
127+
- id: deploy-st2-advanced
128+
name: Deploy StackStorm with extra Ansible vars
129+
uses: bitovi/github-actions-deploy-stackstorm@main
130+
with:
131+
aws_default_region: us-east-1
132+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID}}
133+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
134+
st2_auth_username: ${{ secrets.ST2_AUTH_USERNAME}}
135+
st2_auth_password: ${{ secrets.ST2_AUTH_PASSWORD}}
136+
# Pass the Ansible vars file
137+
st2_ansible_extra_vars_file: "st2_vars.yaml"
138+
```
139+
140+
We encourage to keep your infrastructure codified!
141+
99142
## Made with BitOps
100143
[BitOps](https://bitops.sh/) allows you to define Infrastructure-as-Code for multiple tools in a central place. This action uses BitOps Docker container with prebuilt deployment tools and [Operations Repository Structure](https://bitops.sh/operations-repo-structure/) to organize the necessary Terraform and Ansible steps, create infrastructure and deploy to it.
101144

action.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ inputs:
5252
st2_packs:
5353
description: 'Comma separated list of packs to install. If you modify this option, be sure to also include `st2` in the list.'
5454
default: "st2"
55-
55+
st2_ansible_extra_vars_file:
56+
description: "Relative path from project root to Ansible vars file. If you'd like to adjust more advanced configuration; st2 version, st2.conf, RBAC, chatops, auth, etc. See https://github.com/stackStorm/ansible-st2#variables for the full list of settings. The Ansible vars will take higher precedence over the GHA inputs."
57+
5658
# Cleanup
5759
tf_stack_destroy:
5860
description: 'Set to "true" to Destroy the created AWS infrastructure for this instance'
@@ -100,6 +102,7 @@ runs:
100102
ST2_AUTH_USERNAME: ${{ inputs.st2_auth_username }}
101103
ST2_AUTH_PASSWORD: ${{ inputs.st2_auth_password }}
102104
ST2_PACKS: ${{ inputs.st2_packs }}
105+
ST2_ANSIBLE_EXTRA_VARS_FILE: ${{ inputs.st2_ansible_extra_vars_file }}
103106
run: |
104107
echo "running operations/_scripts/deploy/deploy.sh"
105108
$GITHUB_ACTION_PATH/operations/_scripts/deploy/deploy.sh

operations/_scripts/deploy/deploy.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ if [ "$STACK_DESTROY" == "true" ]; then
3535
export BITOPS_ANSIBLE_SKIP_DEPLOY="true"
3636
fi
3737

38+
# 'st2_ansible_extra_vars_file' to override the default StackStorm configuration
39+
if [[ -n $ST2_ANSIBLE_EXTRA_VARS_FILE ]]; then
40+
if [[ ! -f $GITHUB_WORKSPACE/$ST2_ANSIBLE_EXTRA_VARS_FILE ]]; then
41+
echo "::error::File '$ST2_ANSIBLE_EXTRA_VARS_FILE' set in 'st2_ansible_extra_vars_file' does not exist!"
42+
exit 1
43+
fi
44+
45+
cp $GITHUB_WORKSPACE/$ST2_ANSIBLE_EXTRA_VARS_FILE $GITHUB_ACTION_PATH/operations/deployment/ansible/
46+
# Ansible var files are prefixed with '@'
47+
export BITOPS_ANSIBLE_EXTRA_VARS="@$(basename $ST2_ANSIBLE_EXTRA_VARS_FILE)"
48+
fi
49+
3850
if [[ "$GHA_TESTING" == "true" ]]; then
3951
echo "Quitting before BitOps invoke"
4052
exit 1

0 commit comments

Comments
 (0)