Created
March 11, 2017 20:45
-
-
Save cnicolov/0969a99809ec58a9df26024297067c38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Some play | |
hosts: localhost | |
connection: local | |
vars: | |
etcd_image: quay.io/coreos/etcd:v3.1.3 | |
etcd_cluster_name: etcd | |
etcd_cluster_size: 5 | |
pre_tasks: | |
- name: "Create list for the initial etcd cluster" | |
set_fact: | |
etcd_initial_cluster: [] | |
- name: "Add {{ etcd_count }} etcds to the initial etcd cluster" | |
set_fact: | |
etcd_initial_cluster: | |
"{{ etcd_initial_cluster + ['%s-%s' | format(etcd_cluster_name, item)] }}" | |
with_sequence: "count={{ etcd_cluster_size }}" | |
- name: "initial cluster addresses" | |
set_fact: | |
etcd_initial_cluster_addresses: >- | |
"{%- for i in etcd_initial_cluster -%} | |
{{ '%s=http://%s:2380' | format(i, i) }} | |
{%- if loop.index < etcd_initial_cluster|length %},{%- endif -%} | |
{%- endfor -%}" | |
tasks: | |
- name: Create a network | |
docker_network: | |
name: etcd | |
- name: Start some containers | |
docker_container: | |
name: "{{ item }}" | |
image: "{{ etcd_image }}" | |
ports: | |
- 2379 | |
- 2380 | |
networks: | |
- name: etcd | |
command: > | |
/usr/local/bin/etcd | |
--name {{ item }} | |
--data-dir=/etcd-data | |
--initial-advertise-peer-urls http://{{ item }}:2380 | |
--listen-peer-urls http://{{ item }}:2380 | |
--advertise-client-urls http://{{ item }}:2379 | |
--listen-client-urls http://{{ item }}:2379 | |
--initial-cluster | |
{{ etcd_initial_cluster_addresses }} | |
--initial-cluster-state new | |
--initial-cluster-token pe6o | |
register: containers_result | |
with_items: "{{ etcd_initial_cluster }}" | |
- name: "Will debug current inventory groups and hosts" | |
debug: | |
msg: "{{ groups }}" | |
when: containers_result|change | |
- name: "Assert that image_{{ etcd_image }} is not available" | |
assert: | |
that: | |
- "('image_%s' | format(etcd_image)) not in groups" | |
when: containers_result|change | |
- name: Refresh inventory | |
include: refresh_inventory.yml | |
static: no | |
when: containers_result|change | |
register: refresh_inventory | |
- assert: | |
that: | |
- 'refresh_inventory|skip' | |
when: containers_result|success | |
- assert: | |
msg: "Assert that group image_{{ etcd_image }} is available" | |
that: | |
- "('image_%s' | format(etcd_image)) in groups" | |
- name: Some other play | |
hosts: "image_{{ etcd_image }}" | |
connection: docker | |
vars: | |
etcd_image: quay.io/coreos/etcd:v3.1.3 | |
tasks: | |
- debug: | |
msg: "{{ inventory_hostname }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: refresh dynamic inventory | |
meta: refresh_inventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrant-ubuntu-trusty-64:~$ ansible-playbook -i ./docker.py playbook.yaml -v | |
No config file found; using defaults | |
PLAY [Some play] *************************************************************** | |
TASK [setup] ******************************************************************* | |
ok: [localhost] | |
TASK [Create list for the initial etcd cluster] ******************************** | |
ok: [localhost] => {"ansible_facts": {"etcd_initial_cluster": []}, "changed": false} | |
TASK [Add {{ etcd_count }} etcds to the initial etcd cluster] ****************** | |
ok: [localhost] => (item=1) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1"]}, "changed": false, "item": "1"} | |
ok: [localhost] => (item=2) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2"]}, "changed": false, "item": "2"} | |
ok: [localhost] => (item=3) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2", "etcd-3"]}, "changed": false, "item": "3"} | |
ok: [localhost] => (item=4) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2", "etcd-3", "etcd-4"]}, "changed": false, "item": "4"} | |
ok: [localhost] => (item=5) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2", "etcd-3", "etcd-4", "etcd-5"]}, "changed": false, "item": "5"} | |
TASK [initial cluster addresses] *********************************************** | |
ok: [localhost] => {"ansible_facts": {"etcd_initial_cluster_addresses": "\"etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380,etcd-4=http://etcd-4:2380,etcd-5=http://etcd-5:2380\""}, "changed": false} | |
TASK [Create a network] ******************************************************** | |
ok: [localhost] => {"ansible_facts": {}, "changed": false} | |
TASK [Start some containers] *************************************************** | |
changed: [localhost] => (item=etcd-1) => {"ansible_facts": {}, "changed": true, "item": "etcd-1"} | |
changed: [localhost] => (item=etcd-2) => {"ansible_facts": {}, "changed": true, "item": "etcd-2"} | |
changed: [localhost] => (item=etcd-3) => {"ansible_facts": {}, "changed": true, "item": "etcd-3"} | |
changed: [localhost] => (item=etcd-4) => {"ansible_facts": {}, "changed": true, "item": "etcd-4"} | |
changed: [localhost] => (item=etcd-5) => {"ansible_facts": {}, "changed": true, "item": "etcd-5"} | |
TASK [Will debug current inventory groups and hosts] *************************** | |
ok: [localhost] => { | |
"msg": { | |
"all": [ | |
"unix://var/run/docker.sock" | |
], | |
"docker_hosts": [ | |
"unix://var/run/docker.sock" | |
], | |
"ungrouped": [ | |
"localhost" | |
] | |
} | |
} | |
TASK [Assert that group image_quay.io/coreos/etcd:v3.1.3 is not available on first run] *** | |
ok: [localhost] => { | |
"changed": false, | |
"msg": "All assertions passed" | |
} | |
TASK [Refresh inventory] ******************************************************* | |
included: /home/vagrant/refresh_inventory.yml for localhost | |
TASK [Assert that refresh_inventory is skipped when not first run] ************* | |
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true} | |
TASK [Assert that group image_quay.io/coreos/etcd:v3.1.3 is available] ********* | |
ok: [localhost] => { | |
"changed": false, | |
"msg": "All assertions passed" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=10 changed=1 unreachable=0 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrant-ubuntu-trusty-64:~$ ansible-playbook -i ./docker.py playbook.yaml -v | |
No config file found; using defaults | |
PLAY [Some play] *************************************************************** | |
TASK [setup] ******************************************************************* | |
ok: [localhost] | |
TASK [Create list for the initial etcd cluster] ******************************** | |
ok: [localhost] => {"ansible_facts": {"etcd_initial_cluster": []}, "changed": false} | |
TASK [Add {{ etcd_count }} etcds to the initial etcd cluster] ****************** | |
ok: [localhost] => (item=1) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1"]}, "changed": false, "item": "1"} | |
ok: [localhost] => (item=2) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2"]}, "changed": false, "item": "2"} | |
ok: [localhost] => (item=3) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2", "etcd-3"]}, "changed": false, "item": "3"} | |
ok: [localhost] => (item=4) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2", "etcd-3", "etcd-4"]}, "changed": false, "item": "4"} | |
ok: [localhost] => (item=5) => {"ansible_facts": {"etcd_initial_cluster": ["etcd-1", "etcd-2", "etcd-3", "etcd-4", "etcd-5"]}, "changed": false, "item": "5"} | |
TASK [initial cluster addresses] *********************************************** | |
ok: [localhost] => {"ansible_facts": {"etcd_initial_cluster_addresses": "\"etcd-1=http://etcd-1:2380,etcd-2=http://etcd-2:2380,etcd-3=http://etcd-3:2380,etcd-4=http://etcd-4:2380,etcd-5=http://etcd-5:2380\""}, "changed": false} | |
TASK [Create a network] ******************************************************** | |
ok: [localhost] => {"ansible_facts": {}, "changed": false} | |
TASK [Start some containers] *************************************************** | |
ok: [localhost] => (item=etcd-1) => {"ansible_facts": {}, "changed": false, "item": "etcd-1"} | |
ok: [localhost] => (item=etcd-2) => {"ansible_facts": {}, "changed": false, "item": "etcd-2"} | |
ok: [localhost] => (item=etcd-3) => {"ansible_facts": {}, "changed": false, "item": "etcd-3"} | |
ok: [localhost] => (item=etcd-4) => {"ansible_facts": {}, "changed": false, "item": "etcd-4"} | |
ok: [localhost] => (item=etcd-5) => {"ansible_facts": {}, "changed": false, "item": "etcd-5"} | |
TASK [Will debug current inventory groups and hosts] *************************** | |
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true} | |
TASK [Assert that group image_quay.io/coreos/etcd:v3.1.3 is not available on first run] *** | |
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true} | |
TASK [Refresh inventory] ******************************************************* | |
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true} | |
TASK [Assert that refresh_inventory is skipped when not first run] ************* | |
ok: [localhost] => { | |
"changed": false, | |
"msg": "All assertions passed" | |
} | |
TASK [Assert that group image_quay.io/coreos/etcd:v3.1.3 is available] ********* | |
ok: [localhost] => { | |
"changed": false, | |
"msg": "All assertions passed" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=8 changed=0 unreachable=0 failed=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment