Last active
March 28, 2017 23:49
-
-
Save gregsymons/741cdf7069bffd4221fb to your computer and use it in GitHub Desktop.
Ansible 2.0 nested task loops don't work
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
> ansible-playbook main.yml -i hosts -c local | |
PLAY *************************************************************************** | |
TASK [setup] ******************************************************************* | |
ok: [localhost] | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"deploy_descriptors": [ | |
{ | |
"artifact1_version": "1.0", | |
"artifact2_version": "1.1", | |
"name": "foo" | |
}, | |
{ | |
"artifact1_version": "1.0", | |
"artifact2_version": "1.0", | |
"name": "bar" | |
} | |
] | |
} | |
TASK [main: deploy the sites in deploy_descriptors] **************************** | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_one_site.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_one_site.yml for localhost | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_one_site: deploy the artifacts for foo] *************************** | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'} deployment_id=0 artifact_base_url=0 artifact_version={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'}" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'} deployment_id=0 artifact_base_url=0 artifact_version={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'}" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'} deployment_id=0 artifact_base_url=0 artifact_version={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'}" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'} deployment_id=0 artifact_base_url=0 artifact_version={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'}" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_one_site: deploy the artifacts for bar] *************************** | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (bar] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.0', u'name': u'bar'} deployment_id=1 artifact_base_url=1 artifact_version={u'artifact1_version': u'1.0', u'artifact2_version': u'1.0', u'name': u'bar'}" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (bar] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.0', u'name': u'bar'} deployment_id=1 artifact_base_url=1 artifact_version={u'artifact1_version': u'1.0', u'artifact2_version': u'1.0', u'name': u'bar'}" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (bar] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.0', u'name': u'bar'} deployment_id=1 artifact_base_url=1 artifact_version={u'artifact1_version': u'1.0', u'artifact2_version': u'1.0', u'name': u'bar'}" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=27 changed=0 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
- set_fact: artifact_base_url='{{item.0}}' artifact_version='{{item.1}}' | |
- name: 'deploy_artifact: inspect the variables in this context ({{ deployment.name }}' | |
debug: msg='deployment={{deployment}} deployment_id={{deployment_id}} artifact_base_url={{artifact_base_url}} artifact_version={{artifact_version}}' |
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
- set_fact: deployment_id={{ item.0 }} deployment={{ item.1 }} | |
- name: 'deploy_one_site: deploy the artifacts for {{ deployment.name }}' | |
include: 'deploy_artifact.yml' | |
with_items: | |
- [ '{{ artifact1_base_url }}', '{{ deployment.artifact1_version }}' ] | |
- [ '{{ artifact2_base_url }}', '{{ deployment.artifact2_version }}' ] |
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
> ansible-playbook main.yml -i hosts -c local | |
PLAY *************************************************************************** | |
TASK [setup] ******************************************************************* | |
ok: [localhost] | |
TASK [debug] ******************************************************************* | |
ok: [localhost] => { | |
"deploy_descriptors": [ | |
{ | |
"artifact1_version": "1.0", | |
"artifact2_version": "1.1", | |
"name": "foo" | |
}, | |
{ | |
"artifact1_version": "1.0", | |
"artifact2_version": "1.0", | |
"name": "bar" | |
} | |
] | |
} | |
TASK [main: deploy the sites in deploy_descriptors] **************************** | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_one_site.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_one_site.yml for localhost | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_one_site: deploy the artifacts for foo] *************************** | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'} deployment_id=0 artifact_base_url=https://artifacts.example.com/repo/artifact1 artifact_version=1.0" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'} deployment_id=0 artifact_base_url=https://artifacts.example.com/repo/artifact2 artifact_version=1.1" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_one_site: deploy the artifacts for bar] *************************** | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
included: /Users/gregsymons/projects/personal/ansible2_nested_loops/deploy_artifact.yml for localhost | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.0', u'name': u'bar'} deployment_id=1 artifact_base_url=https://artifacts.example.com/repo/artifact1 artifact_version=1.0" | |
} | |
TASK [set_fact] **************************************************************** | |
ok: [localhost] | |
TASK [deploy_artifact: inspect the variables in this context (foo] ************* | |
ok: [localhost] => { | |
"msg": "deployment={u'artifact1_version': u'1.0', u'artifact2_version': u'1.1', u'name': u'foo'} deployment_id=1 artifact_base_url="https://artifacts.example.com/repo/artifact2" artifact_version=1.0" | |
} | |
PLAY RECAP ********************************************************************* | |
localhost : ok=27 changed=0 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
[localhost] | |
localhost | |
[localhost:vars] |
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
--- | |
- hosts: localhost | |
vars: | |
deploy_descriptors: | |
- name: 'foo' | |
artifact1_version: '1.0' | |
artifact2_version: '1.1' | |
- name: 'bar' | |
artifact1_version: '1.0' | |
artifact2_version: '1.0' | |
artifact1_base_url: 'https://artifacts.example.com/repo/artifact1' | |
artifact2_base_url: 'https://artifacts.example.com/repo/artifact2' | |
tasks: | |
- debug: var='deploy_descriptors' | |
- name: 'main: deploy the sites in deploy_descriptors' | |
include: 'deploy_one_site.yml' | |
with_indexed_items: '{{ deploy_descriptors }}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment