Skip to content

Instantly share code, notes, and snippets.

@childnode
Last active February 16, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save childnode/50295370e2fc79a10847411826210de2 to your computer and use it in GitHub Desktop.
Save childnode/50295370e2fc79a10847411826210de2 to your computer and use it in GitHub Desktop.
.Python
bin/
include/
lib/
pip-selfcheck.json
playbook.retry
#!/usr/bin/env sh
docker build --tag childnode/bugreport-ansible-docker-container:latest -f Dockerfile $(dirname $0)/
[localhost]
127.0.0.1
---
- name: "Bugreport 36243 - https://github.com/ansible/ansible/issues/36243"
connection: local
hosts: localhost
vars:
dstate: "{{state | default('started')}}"
env: { foo: 'bar', bar: 'foo', baz: 'zap' }
tasks:
- name: "inspect env for container has been changed {{result.changed}}"
local_action: shell {% raw %}docker inspect de.childno.bugreport.ansible-docker-container -f '{{.Config.Env}}'{% endraw %}
register: inspected
- name: "start container {{dstate}} with {{env}}"
docker_container:
name: "de.childno.bugreport.ansible-docker-container"
hostname: "de.childno.bugreport.ansible-docker-container"
image: "childnode/bugreport-ansible-docker-container:latest"
state: "{{dstate}}"
#restart: "omit"
#recreate: "omit"
pull: "false"
restart_policy: "unless-stopped"
# restart_retries: "omit"
# volumes: "omit"
# published_ports: "omit"
# exposed_ports: "omit"
env: '{{env}}'
# env_file: "omit"
# log_driver: "json-file"
# log_options: "{'max-file': '3','max-size': '200m'}"
# network_mode: "bridge"
# keep_volumes: "false"
# command: "omit"
# etc_hosts: "omit"
# user: "omit"
# privileged: "omit"
register: result
- debug:
msg:
- "was:"
- "{{inspected.stdout}}"
- "is now:"
- "{{result.ansible_facts.docker_container.Config.Env}}"
- "expected to match applied:"
- "{{env}}"
...
#!/usr/bin/env sh
ansible-playbook playbook.yml --list-hosts
ansible-playbook playbook.yml -e state=present
ansible-playbook playbook.yml
#docker inspect de.childno.bugreport.ansible-docker-container -f "{{.Config.Env}}"
echo "show nothing changes if we do present again"
ansible-playbook playbook.yml -e state=present
#docker inspect de.childno.bugreport.ansible-docker-container -f "{{.Config.Env}}"
echo "show nothing changes if we start with different env, only containing one of the three envs defined before"
ansible-playbook playbook.yml -v -e '{"env": {foo: bar}}'
#docker inspect de.childno.bugreport.ansible-docker-container -f "{{.Config.Env}}"
echo "show changes if we start with different env, containing a different than one of the three envs defined before"
ansible-playbook playbook.yml -e '{"env": {changed: me}}'
#docker inspect de.childno.bugreport.ansible-docker-container -f "{{.Config.Env}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment