Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pack config #42

Open
nicholasamorim opened this issue Sep 11, 2019 · 3 comments
Open

Support pack config #42

nicholasamorim opened this issue Sep 11, 2019 · 3 comments
Labels

Comments

@nicholasamorim
Copy link

Would it make sense to have certain things as pack config? Very much like ansible.cfg in a way.

The config could set variables that are commonly used across all runs such as:

private_key
inventory_file
and some global env values if need be.

@punkrokk
Copy link

punkrokk commented Sep 11, 2019

Can you expand on this thinking @nicholasamorim. I think I know where you are going with this as I have some of this in a fork, but if you could define your requirements in a more complete way it will help everyone hone in on a path forward.

Btw - wouldn't one wish to store things like a private_key in an encrypted datastore value?

@nicholasamorim
Copy link
Author

nicholasamorim commented Sep 12, 2019

Well, in my specific case, I had to set:

ANSIBLE_SSH_USER to stanley using the env and set the private_key as well as cwd every time I use ansible.playbook.

I know that this stuff can be circumvented by using env vars as well as abstracting the ansible.playbook behind a ST2 workflow.

But I just think it would be nice to provide a set of defaults in /opt/stackstorm/configs/ansible.yaml so that every action would run with them by default. If this would support retrieving from the KV even better.

cwd is a pretty clear case as a lot of people tend to have their playbooks in a single repo/folder in the filesystem.

So an example:

cwd: "/path/to/my/plays"
inventory_file: "envs/{{ st2kv('system.ENV') }}/hosts"
private_key: "/home/stanley/.ssh/stanley_rsa"
env:
   ANSIBLE_SSH_USER: stanley
   ANOTHER_DEFAULT_ENV_VAR: myvalue

So these would always be used unless overriden at the action level.

Does that make sense?

@arm4b
Copy link
Member

arm4b commented Sep 12, 2019

I'm 👍 with adding additional env to the Ansible pack config, as Ansible exposes every configuration setting as ENV variable.

This way, most of the configuration could be set via ENV and implementation is easy and convenient with current way how the pack is designed as we just need to pass those envs to Ansible execution. As a bonus, variable precedence is on our side when additional CLI params would override ENVs in default Ansible behavior.

Configuration you mentioned above could be transformed to respective env vars:
ANSIBLE_INVENTORY, ANSIBLE_PRIVATE_KEY_FILE, ANSIBLE_SSH_USER

See: https://github.com/ansible/ansible/blob/devel/lib/ansible/config/base.yml for the full list.

@arm4b arm4b added the feature label Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants