Skip to content

Instantly share code, notes, and snippets.

@mohclips
Created February 6, 2017 20:19
Show Gist options
  • Save mohclips/425525cdbf6d93144aac9bc32e3276fe to your computer and use it in GitHub Desktop.
Save mohclips/425525cdbf6d93144aac9bc32e3276fe to your computer and use it in GitHub Desktop.
Ansible - Check if Shipyard is installed as a docker image, if not install it
#
# Block to install Shipyard onto docker_swarm_manager - if required
#
- block:
- name: "Check if Shipyard is installed"
shell: docker ps | grep -c "shipyard/shipyard"
ignore_errors: yes
become: no
register: shipyard_test
- debug: var=shipyard_test
- debug: msg="success"
when: shipyard_test|success
- debug: msg="failed"
#when: shipyard_test.failed == true
when: shipyard_test|failed
- name: "Install Shipyard on docker_swarm_manager"
shell: curl -s https://shipyard-project.com/deploy | bash -s
when: shipyard_test|failed
when: "{{ inventory_hostname in groups['docker_swarm_manager'][0] }}"
delegate_to: "{{ groups['docker_swarm_manager'][0] }}"
@mohclips
Copy link
Author

mohclips commented Feb 6, 2017

The block "when" only runs when the hostname matches the first name in the group
The delegate_to runs all commands on the first hostname in the group.
I use the "shell" module as i am piping the output into something else.
ignore_errors is used as grep will fail if it doesnt match and we need to know about that, rather than stop the play

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment