Created
February 6, 2017 20:19
-
-
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
This file contains hidden or 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
# | |
# 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] }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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