Skip to content

Commit

Permalink
run, stop and kill added
Browse files Browse the repository at this point in the history
  • Loading branch information
arssher committed Oct 8, 2014
1 parent f6ee1cc commit 443bc63
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 16 deletions.
4 changes: 3 additions & 1 deletion group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
ssh_port_to_expose: 2222
container_names:
- hello
- pullo
- sober_tesla
- drunk_tesla

#node01: {name: 'hello'}
2 changes: 1 addition & 1 deletion hosts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ docker-host-nodes
docker-containers

[ansible-master]
localhost ansible_ssh_port=22
localhost ansible_ssh_port=22 node=node01
3 changes: 2 additions & 1 deletion shutdown.yml → kill.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---

#accepts one argument - container name
- hosts: docker-host-nodes
sudo: yes
roles:
- shutdown
- kill

5 changes: 5 additions & 0 deletions roles/kill/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

- name: shutdown docker
docker: state=absent name={{ container_name }} image=ubuntu/sshjdk:14.04

16 changes: 9 additions & 7 deletions roles/run/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
---

- name: Get facts about launched docker containers
docker_facts:

- name: check running containers
fail: msg="container {{ item }} already running. Stop it first!"
when: docker_containers.{{ item }} is defined and docker_containers.{{ item }}.docker_state.Running
with_items: container_names

- name: run container
#this should be changed in non-local mode: net=host only
docker: state=running hostname={{ container_name }} name={{ container_name }} image=ubuntu/sshjdk:14.04 net=bridge ports=2222 count=1 privileged=yes

# the rest of this file should be removed in non-local mode: we don't need to add containers to inventory
- name: Get facts about launched docker containers
docker_facts:

- name: hello list
fail: msg="container already running"
when: docker_containers.{{ item }} is defined
with_items: container_names

# the rest of this file should be removed in non-local mode: we don't need to add containers to hosts
# add created containers to [docker-containers]
- name: add containers to [docker-containers]
add_host: hostname={{item.key}} ansible_ssh_host=172.17.42.1 ansible_ssh_port={{item.value.docker_ports[0].PublicPort}} ansible_ssh_user=root groups=docker-containers
Expand Down
6 changes: 0 additions & 6 deletions roles/shutdown/tasks/main.yml

This file was deleted.

5 changes: 5 additions & 0 deletions roles/stop/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

- name: shutdown docker
docker: state=stopped name={{ container_name }} image=ubuntu/sshjdk:14.04

1 change: 1 addition & 0 deletions run.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---

#accepts one argument - container name
- hosts: docker-host-nodes
sudo: yes
roles:
Expand Down
8 changes: 8 additions & 0 deletions stop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

#accepts one argument - container name
- hosts: docker-host-nodes
sudo: yes
roles:
- stop

0 comments on commit 443bc63

Please sign in to comment.