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

docker: support referencing env vars in rolecule.yml #15

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

gurpalw
Copy link
Contributor

@gurpalw gurpalw commented Oct 16, 2024

I needed a way to reference local AWS credentials, to test a role that downloaded something from S3 via the AWS env vars.

I'm not sure if there's an existing way of doing this via rolecule, but this seems to work very well.

If the string contains an environment variable (like $MY_VAR, or ${MY_VAR}) and the environment variable is set, it expands the value. If no environment variable is present or recognized, it leaves the string unchanged. If part of the string contains variables and other parts are plain strings, it only expands the variables and leaves the rest as is.

example usage:

rolecule.yml:

---
engine:
  name: docker

provisioner:
  name: ansible
  env:
    ANSIBLE_HASH_BEHAVIOUR: merge
    AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
    AWS_SESSION_TOKEN: $AWS_SESSION_TOKEN

verifier:
  name: goss

instances:
  - name: ubuntu-22.04
    image: x.dkr.ecr.eu-west-1.amazonaws.com/ubuntu-22.04-systemd-dind:1.1

playbook.yml:

---
- name: test
  hosts: localhost
  roles:
    - role: sentinel
  vars:
    aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
    aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
    aws_security_token: "{{ lookup('env', 'AWS_SESSION_TOKEN') }}"

@z0mbix z0mbix merged commit 396f2d5 into z0mbix:main Oct 16, 2024
2 checks passed
@gurpalw gurpalw deleted the support-env-vars branch October 17, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants