blob: c28eae61fa4a6ef41ef80503c5faa90fcb49511d [file] [log] [blame]
Matteo Scandolof0441032017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Scott Bakerb63ea792016-08-11 10:24:48 -070017---
18- hosts: {{ instance_name }}
19 gather_facts: False
20 connection: ssh
21 user: {{ username }}
Sapan Bhatia2fb68782017-02-07 11:32:56 -080022 become: yes
Scott Bakerb63ea792016-08-11 10:24:48 -070023
24 vars:
25 container_name: {{ container_name }}
26 docker_image: {{ docker_image }}
27 network_method: {{ network_method }}
28 ports:
29 {% for port in ports %}
30 - device: {{ port.device }}
31 xos_network_id: {{ port.xos_network_id }}
32 mac: {{ port.mac|default("") }}
33 ip: {{ port.ip }}
34 snoop_instance_mac: {{ port.snoop_instance_mac }}
35 snoop_instance_id: {{ port.snoop_instance_id }}
36 parent_mac: {{ port.parent_mac|default("") }}
37 s_tag: {{ port.s_tag|default("") }}
38 c_tag: {{ port.c_tag|default("") }}
39 next_hop: {{ port.next_hop|default("") }}
40 bridge: {{ port.bridge }}
41 {% endfor %}
42 volumes:
43 {% for volume in volumes %}
44 - {{ volume }}
45 {% endfor %}
46
47 tasks:
48
49# - name: Fix /etc/hosts
50# lineinfile:
51# dest=/etc/hosts
52# regexp="127.0.0.1 localhost"
53# line="127.0.0.1 localhost {{ instance_hostname }}"
54
55 - name: Add repo key
56 apt_key:
57 keyserver=hkp://pgp.mit.edu:80
58 id=58118E89F3A912897C070ADBF76221572C52609D
59
60 - name: Install Docker repo
61 apt_repository:
62 repo="deb https://apt.dockerproject.org/repo ubuntu-trusty main"
63 state=present
64
65 - name: Install Docker
66 apt:
67 name={{ '{{' }} item {{ '}}' }}
68 state=latest
69 update_cache=yes
70 with_items:
71# XXX docker 1.10 is not working on cloudlab
72# - docker-engine
73 - python-pip
74 - python-httplib2
75
76 - name: Install Docker 1.9.1
77 apt:
78 name={{ '{{' }} item {{ '}}' }}
79 update_cache=yes
80 with_items:
81 - docker-engine=1.9.1-0~trusty
82
83 # Something is installing a requests library that is incompative with pip, and
84 # will cause this recipe to fail next time it tries to run pip. Only the one
85 # in /usr/local/lib is bad. There's still a good one in /usr/lib
86 - name: check if bad requests library installed
87 stat: path=/usr/local/lib/python2.7/dist-packages/requests
88 register: bad_requests
89
90 - name: remove bad request library
91 shell: mv /usr/local/lib/python2.7/dist-packages/requests /usr/local/lib/python2.7/dist-packages/requests-bad
92 when: bad_requests.stat.exists == True
93
94 - name: Install docker-py
95 pip:
96 name=docker-py
97 state=latest
98
99 - name: install Pipework
100 get_url: url=https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework
101 dest=/usr/local/bin/pipework
102 mode=0755
103
104# - name: Start Container
105# docker:
106# docker_api_version: "1.18"
107# name: {{ container_name }}
108# # was: reloaded
109# state: running
110# image: {{ docker_image }}
111
112 - name: check if systemd is installed
113 stat: path=/usr/bin/systemctl
114 register: systemctl
115
116 - name: container upstart
117 template: src=/opt/xos/synchronizers/openstack/templates/container.conf.j2 dest=/etc/init/container-{{ container_name }}.conf
118
119 - name: container systemd
120 template: src=/opt/xos/synchronizers/openstack/templates/container.service.j2 dest=/lib/systemd/system/container-{{ container_name }}.service
121
122 - name: container startup script
123 template: src=/opt/xos/synchronizers/openstack/templates/start-container.sh.j2 dest=/usr/local/sbin/start-container-{{ container_name }}.sh mode=0755
124
125 - name: container teardown script
126 template: src=/opt/xos/synchronizers/openstack/templates/stop-container.sh.j2 dest=/usr/local/sbin/stop-container-{{ container_name }}.sh mode=0755
127
128 - name: restart systemd
129 shell: systemctl daemon-reload
130 when: systemctl.stat.exists == True
131
132{% if ports %}
133 - name: make sure bridges are setup
134 shell: ifconfig {{ '{{' }} item.bridge {{ '}}' }}
135 with_items: "ports"
136{% endif %}
137
138 - name: Make sure container is running
139 service: name=container-{{ container_name }} state=started
140