Skip to content

Commit 3009103

Browse files
author
armab
committed
Update st2_user_data to take raw data as input as an alternative to file path
1 parent d1268e1 commit 3009103

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.2.0
4+
- Update `st2_user_data` to take raw data as input as an alternative to file path.
5+
36
## 1.1.1
47

58
- Use non-deprecated runner name and change ``runner_type`` from ``run-remote`` to

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,22 @@ break the configuration where iam roles are being used
5555

5656
## st2_user_data
5757

58-
Optionally, you can set the user_data to set a default file to be used during new instance
59-
creation. Put your user_data file somewhere accessible by the StackStorm user, and use
60-
the st2_user_data config option to set it.
58+
Optionally, you can add the [`user_data`](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html) with set of provisioning instructions to be used during the new instance
59+
creation.
6160

6261
```yaml
6362
st2_user_data: "/full/path/to/file"
6463
```
65-
64+
Put your user_data file somewhere accessible by the StackStorm user, and use the st2_user_data config option to set it.
6665
This file/script will be used for all invocations of the ec2_run_instances action
6766
67+
Alternatively, user data can be specified inline:
68+
```yaml
69+
st2_user_data: |
70+
#!/bin/bash
71+
echo "I'm EC2 user data: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html"
72+
```
73+
6874
## Actions
6975
7076
Prior to installation of the aws pack, you can get the list of available actions here:

actions/lib/action.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
import eventlet
34
import importlib
@@ -22,18 +23,20 @@ def __init__(self, config):
2223
'aws_access_key_id': None,
2324
'aws_secret_access_key': None
2425
}
25-
self.user_data_file = config.get('st2_user_data', None)
2626
self.debug = config.get('debug', False)
2727

2828
self.userdata = None
29-
30-
# Read in default user data
31-
if self.user_data_file:
32-
try:
33-
with open(self.user_data_file, 'r') as fp:
34-
self.userdata = fp.read()
35-
except IOError as e:
36-
self.logger.error(e)
29+
if config.get('st2_user_data', None):
30+
# Check if string "looks" like a normal absolute path
31+
if os.path.isabs(config['st2_user_data']) and '\n' not in config['st2_user_data']:
32+
# Read in default user data from file
33+
try:
34+
with open(config['st2_user_data'], 'r') as fp:
35+
self.userdata = fp.read()
36+
except IOError as e:
37+
self.logger.error(e)
38+
else:
39+
self.userdata = config['st2_user_data']
3740

3841
# Note: In old static config credentials and region are under "setup" key and with a new
3942
# dynamic config values are top-level

actions/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def run(self, **kwargs):
2222

2323
if user_data:
2424
self.logger.info('Passing in default user_data specified as st2_user_data config '
25-
'option (%s file)' % (self.user_data_file))
25+
'option (%s ...)' % (self.st2_user_data()[:15]))
2626
kwargs['user_data'] = self.st2_user_data()
2727
if aws_action == 'create_tags':
2828
# Skip "Tags" parameter and pass "tags" as is unless it is a string.

config.schema.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
required: true
1616
default: 'us-east-1'
1717
st2_user_data:
18-
description: "The file for all invocations of the 'aws.ec2_run_instances' action"
18+
description: >
19+
Raw content or filepath with EC2 user data: automated configuration tasks or scripts executed after the instance starts.
20+
Used as default for all 'ec2_run_instances' invocations if no custom user-data provided via action parameters.
1921
type: "string"
2022
debug:
2123
type: "boolean"

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ keywords:
2020
- lambda
2121
- kinesis
2222

23-
version : 1.1.1
23+
version : 1.2.0
2424
author : StackStorm, Inc.
2525

0 commit comments

Comments
 (0)