Quick lookup plugin for ansible. I needed a clean way to pass an unknown amount of local envs via params when creating a docker container, based on the env vars on the CI server.
Run the playbook to test with: ansible-playbook -i localhost, playbook.yml
Note: This was thrown together very quickly, I'll hopfully have some time to expand this plugin with proper documention and error handling.
Note original (non plugin route was) ugly and hacky:
---
- name: Get all local envs for dynamic docker injection
shell: env | grep ^SEARCH_PREFIX_
# When nothing found by grep return code is 1, this is fine.
ignore_errors: yes
register: app_envs
- name: Build list of docker app params
shell: |
echo "{% for x in app_envs.stdout_lines %}
-e {{ "{}={}".format(x.split('=', 1)[0], x.split('=', 1)[1].replace('\"','\\\"')) }}
{% endfor %}
"
register: docker_env_params