blob: a9d2ec684d4ef1ca915f39984ee54a012f208515 [file] [log] [blame]
Matteo Scandolo3896c472017-08-01 13:31:42 -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
Andy Baviera17d84b2016-11-16 09:39:26 -080017---
18# file: create-lxd/tasks/main.yml
Andy Baviera17d84b2016-11-16 09:39:26 -080019
Zack Williams5223dd92017-02-28 23:38:02 -070020- name: Enable trusty-backports apt repository
Andy Baviera17d84b2016-11-16 09:39:26 -080021 apt_repository:
22 repo: "{{ item }}"
23 state: present
24 with_items:
Zack Williams5223dd92017-02-28 23:38:02 -070025 - "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse"
Andy Baviera17d84b2016-11-16 09:39:26 -080026
Zack Williams5223dd92017-02-28 23:38:02 -070027- name: Install LXD from trusty-backports
Andy Baviera17d84b2016-11-16 09:39:26 -080028 apt:
29 name: lxd
Andy Baviera17d84b2016-11-16 09:39:26 -080030 default_release: trusty-backports
Zack Williams5223dd92017-02-28 23:38:02 -070031 update_cache: yes
32 cache_valid_time: 3600
Andy Baviera17d84b2016-11-16 09:39:26 -080033
Zack Williams5223dd92017-02-28 23:38:02 -070034- name: Create LXD profiles for OpenStack services
Andy Baviera17d84b2016-11-16 09:39:26 -080035 lxd_profile:
Zack Williams5223dd92017-02-28 23:38:02 -070036 name: "openstack-{{ item.name }}"
Andy Baviera17d84b2016-11-16 09:39:26 -080037 state: present
38 config:
39 user.user-data: |
40 #cloud-config
41 ssh_authorized_keys:
Zack Williams5223dd92017-02-28 23:38:02 -070042 - "{{ lookup('file', ssh_pki_dir ~ '/client_certs/{{ pod_sshkey_name }}_sshkey.pub') }}"
43 description: 'OpenStack service {{ item.name }} for CORD'
Andy Baviera17d84b2016-11-16 09:39:26 -080044 devices:
45 eth0:
Andy Baviera17d84b2016-11-16 09:39:26 -080046 type: nic
Zack Williams5223dd92017-02-28 23:38:02 -070047 parent: mgmtbr
48 nictype: bridged
49 # ipv4.address: "{{ mgmt_ipv4_first_octets }}.{{ item.ipv4_last_octet }}"
50 hwaddr: "{{ item.hwaddr | default(hwaddr_prefix ~ ((mgmt_ipv4_first_octets ~ '.' ~ item.ipv4_last_octet) | ip4_hex)) | hwaddr('unix') }}"
Andy Bavier1cac0012017-03-13 10:06:18 -040051 certs:
52 type: disk
53 path: /usr/local/share/ca-certificates/cord/
54 source: /usr/local/share/ca-certificates/
Zack Williams5223dd92017-02-28 23:38:02 -070055 with_items: "{{ head_lxd_list }}"
Andy Baviera17d84b2016-11-16 09:39:26 -080056
57- name: Create containers for the OpenStack services
Andy Baviera17d84b2016-11-16 09:39:26 -080058 lxd_container:
59 name: "{{ item.name }}"
60 architecture: x86_64
61 state: started
62 source:
63 type: image
64 mode: pull
65 server: https://cloud-images.ubuntu.com/releases
66 protocol: simplestreams
67 alias: "{{ ansible_distribution_release }}"
Zack Williams5223dd92017-02-28 23:38:02 -070068 profiles: ["openstack-{{ item.name }}"]
Andy Baviera17d84b2016-11-16 09:39:26 -080069 wait_for_ipv4_addresses: true
70 timeout: 600
71 with_items: "{{ head_lxd_list }}"
72
73- name: fetch IP of DHCP harvester
Zack Williamsfe284a12017-07-01 11:00:04 -070074 when: use_maas
Andy Baviera17d84b2016-11-16 09:39:26 -080075 command: docker-ip harvester
76 register: harvester_ip
77 changed_when: False
78
79- name: force a harvest to get container name resolution
Zack Williamsfe284a12017-07-01 11:00:04 -070080 when: use_maas
Andy Baviera17d84b2016-11-16 09:39:26 -080081 uri:
82 url: http://{{ harvester_ip.stdout }}:8954/harvest
83 method: POST
84
85- name: wait for container name resolution
Zack Williamsfe284a12017-07-01 11:00:04 -070086 when: use_maas
Andy Baviera17d84b2016-11-16 09:39:26 -080087 host_dns_check:
88 hosts: "{{ head_lxd_list | map(attribute='name') | list | to_json }}"
89 command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest"
90 register: all_resolved
91 until: all_resolved.everyone == "OK"
92 retries: 5
93 delay: 10
94 failed_when: all_resolved.everyone != "OK"
95
Zack Williams43d62b52017-01-23 07:34:45 -070096- name: Wait for containers to be accessible via SSH
Andy Baviera17d84b2016-11-16 09:39:26 -080097 wait_for:
Zack Williams43d62b52017-01-23 07:34:45 -070098 host: "{{ item.name }}"
99 port: 22
100 search_regex: "OpenSSH"
Andy Baviera17d84b2016-11-16 09:39:26 -0800101 with_items: "{{ head_lxd_list }}"
102
Sapan Bhatia35dba662017-04-18 13:32:28 +0200103- name: Ensure /etc/ansible directory exists
Zack Williams5223dd92017-02-28 23:38:02 -0700104 file:
105 path: /etc/ansible
106 state: directory
107 owner: root
108 group: root
109 mode: 0755
Sapan Bhatia35dba662017-04-18 13:32:28 +0200110
Zack Williams5223dd92017-02-28 23:38:02 -0700111- name: Create /etc/ansible/hosts file with containers list
Andy Baviera17d84b2016-11-16 09:39:26 -0800112 template:
Zack Williams5223dd92017-02-28 23:38:02 -0700113 src: ansible_hosts.j2
114 dest: /etc/ansible/hosts
115 owner: root
116 group: root
117 mode: 0644
Andy Baviera17d84b2016-11-16 09:39:26 -0800118