Ansible - Conditionally set volume and tls hostname based on inventory file in docker module -


i'm using ansible deploy containers production. during development, i'd have ansible deploy containers on localhost instead of production servers.

production servers run on ubuntu, localhost os x boot2docker.

i have 2 inventory files, production , localhost. dir structure looks this:

. |--inventories |  |localhost |  |production | |--group_vars |  |all |  |localhost |  |production | |--roles |  |--web |     |--tasks          |main.yml | |web.yml  

web.yml defines host group , assigns web role.

/roles/web/tasks/main.yml looks this:

- name: run web container   docker:     name: web     image: some/image     state: reloaded     ...     tls_hostname: boot2docker     volumes:       - "/data/db:/data/db"     env:       ...   tags:     - ... 

i need set tls_hostname conditionally, if localhost inventory used; likewise, want set volume if production inventory file used.

very new ansible - seems i'm not approaching right way there's easier way this? want avoid creating separate tasks deploy locally; need way define volume , tls_hostname conditionally (and leave @ default setting otherwise)

as of ansible 1.8, can omit variables , module parameters using default filter special omit value. example,

- name: run web container   docker:     name: web     image: some/image     state: reloaded     ...     tls_hostname: "{{ hostname | default('some default value') }}"     volumes: "{{ volumes | default(omit) }}"     env:       ...   tags:     - ... 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -