Skip to content

Instantly share code, notes, and snippets.

@Hounddog
Created October 4, 2017 12:03
Show Gist options
  • Save Hounddog/27722348a19e77e0b630203efd91a283 to your computer and use it in GitHub Desktop.
Save Hounddog/27722348a19e77e0b630203efd91a283 to your computer and use it in GitHub Desktop.
Iterate only when changed
"Repositories": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"after": "2bebc339d977194c9029310a3f1f49dac2ea61ee",
"before": "2bebc339d977194c9029310a3f1f49dac2ea61ee",
"changed": false,
"invocation": {
"module_args": {
"accept_hostkey": true,
"bare": false,
"clone": true,
"depth": null,
"dest": "/efs-gp/AWSTEST/ansible/rocketchat/",
"executable": null,
"force": false,
"key_file": null,
"recursive": true,
"reference": null,
"refspec": null,
"remote": "origin",
"repo": "[email protected]:DOC-Compose/rocketchat.git",
"ssh_opts": null,
"track_submodules": false,
"umask": null,
"update": true,
"verify_commit": false,
"version": "feature-swarm-mode"
}
},
"item": {
"key": "rocketchat",
"value": {
"git": {
"branch": "feature-swarm-mode",
"repo": "[email protected]:DOC-Compose/rocketchat.git"
}
}
},
"remote_url_changed": false
},
tasks:
- name: Clone Repositories
git:
accept_hostkey: true
repo: "{{ item.value.git.repo }}"
dest: "{{destination}}/{{item.key}}/"
version: "{{item.value.git.branch}}"
register: Repositories
with_dict: "{{ services }}"
- name: Debug managed
debug:
var: Repositories
- name: Deploy Services
shell: docker stack deploy -c {{ destination }}/{{ item.key }}/docker-compose.yml {{ item.key }}
args:
chdir: "{{ destination }}/{{ item.key }}"
with_dict: "{{ Repositories }}"
when: {{ Repositories.item.changed }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment