StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html

Home Page:https://stackstorm.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Environment variables from file in Actions

jesvilnie opened this issue · comments

Having the possibility to define environment variables in the Actions is crucial in most situations, but it would be really nice to have the possibility to specify these variables from a file, so they can be reused across multiple actions without the need of replicate the list of env vars in each action.

It would be something like this:

---
name: "my_script"
runner_type: "remote-shell-cmd"
description: "Remote CMD with envs form file"
enabled: true
env_file: "/path/to/my/env/file"

Or as a parameter:

---
name: "my_script"
runner_type: "remote-shell-cmd"
description: "Remote CMD with envs form file"
enabled: true
parameters:
    env_file: 
       type: "string"
       default: "/path/to/my/env/file"

I think we can write an application package, put the environment variable configuration in the package configuration, and then use this configuration for all the actions in this package.

A workaround to get this functionality would be to provide a json file with the environment variables that is read in an action prior to calling core.remote and then pass the contents via the env parameter.

For example (not tested)

/path/to/action_env.json

{
  "username": "user1",
  "url": "https://example.com/",
  "project_id": "abcd2134"
}

Load the environment file. StackStorm will automatically deserialise JSON content from stdout. The deserialised JSON can be published for use in subsequent actions.

  load_env:
    action: core.local
    input:
      - cmd: cat /path/to/action_env.json
    next:
      - do: run_remote_cmd
        when: <% succeeded() %>
        publish:
          env_kw: <%  result().stdout %>

  run_remote_cmd:
    action: core.remote
    input:
        hosts: somehost.example.com
        env: <% ctx().env_kw %>
        cmd: "echo $USERNAME $URL $PROJECT_ID"