blob: 88c87a263e90105e9f357a37f5e97789ac02a25d [file] [log] [blame]
Zack Williams2f5f2bd2017-12-01 15:04:22 -07001---
Matteo Scandolo3896c472017-08-01 13:31:42 -07002# 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
Andy Baviera17d84b2016-11-16 09:39:26 -080016# file: create-lxd/tasks/main.yml
Andy Baviera17d84b2016-11-16 09:39:26 -080017
Zack Williams5223dd92017-02-28 23:38:02 -070018- name: Enable trusty-backports apt repository
Andy Baviera17d84b2016-11-16 09:39:26 -080019 apt_repository:
20 repo: "{{ item }}"
21 state: present
22 with_items:
Zack Williams5223dd92017-02-28 23:38:02 -070023 - "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse"
Andy Baviera17d84b2016-11-16 09:39:26 -080024
Zack Williams5223dd92017-02-28 23:38:02 -070025- name: Install LXD from trusty-backports
Andy Baviera17d84b2016-11-16 09:39:26 -080026 apt:
27 name: lxd
Andy Baviera17d84b2016-11-16 09:39:26 -080028 default_release: trusty-backports
Zack Williams5223dd92017-02-28 23:38:02 -070029 update_cache: yes
30 cache_valid_time: 3600
Andy Baviera17d84b2016-11-16 09:39:26 -080031
Zack Williams5223dd92017-02-28 23:38:02 -070032- name: Create LXD profiles for OpenStack services
Andy Baviera17d84b2016-11-16 09:39:26 -080033 lxd_profile:
Zack Williams5223dd92017-02-28 23:38:02 -070034 name: "openstack-{{ item.name }}"
Andy Baviera17d84b2016-11-16 09:39:26 -080035 state: present
36 config:
37 user.user-data: |
38 #cloud-config
39 ssh_authorized_keys:
Zack Williams5223dd92017-02-28 23:38:02 -070040 - "{{ lookup('file', ssh_pki_dir ~ '/client_certs/{{ pod_sshkey_name }}_sshkey.pub') }}"
41 description: 'OpenStack service {{ item.name }} for CORD'
Andy Baviera17d84b2016-11-16 09:39:26 -080042 devices:
43 eth0:
Andy Baviera17d84b2016-11-16 09:39:26 -080044 type: nic
Zack Williams2f5f2bd2017-12-01 15:04:22 -070045 parent: "{{ management_net_bridge }}"
Zack Williams5223dd92017-02-28 23:38:02 -070046 nictype: bridged
Zack Williams6e1d8162018-01-31 15:29:55 -070047 hwaddr: "{{ item.hwaddr | default( vtn_net_management_host_hwaddr_prefix ~ ( vtn_net_management_host_cidr | ipaddr(item.ipv4_last_octet) | ipaddr('address') | ip4_hex )) | hwaddr('linux') }}"
Andy Bavier1cac0012017-03-13 10:06:18 -040048 certs:
49 type: disk
50 path: /usr/local/share/ca-certificates/cord/
51 source: /usr/local/share/ca-certificates/
Zack Williams5223dd92017-02-28 23:38:02 -070052 with_items: "{{ head_lxd_list }}"
Andy Baviera17d84b2016-11-16 09:39:26 -080053
54- name: Create containers for the OpenStack services
Andy Baviera17d84b2016-11-16 09:39:26 -080055 lxd_container:
56 name: "{{ item.name }}"
57 architecture: x86_64
58 state: started
59 source:
60 type: image
61 mode: pull
62 server: https://cloud-images.ubuntu.com/releases
63 protocol: simplestreams
64 alias: "{{ ansible_distribution_release }}"
Zack Williams5223dd92017-02-28 23:38:02 -070065 profiles: ["openstack-{{ item.name }}"]
Andy Baviera17d84b2016-11-16 09:39:26 -080066 wait_for_ipv4_addresses: true
67 timeout: 600
68 with_items: "{{ head_lxd_list }}"
69
70- name: fetch IP of DHCP harvester
Zack Williamsfe284a12017-07-01 11:00:04 -070071 when: use_maas
Andy Baviera17d84b2016-11-16 09:39:26 -080072 command: docker-ip harvester
73 register: harvester_ip
74 changed_when: False
75
76- name: force a harvest to get container name resolution
Zack Williamsfe284a12017-07-01 11:00:04 -070077 when: use_maas
Andy Baviera17d84b2016-11-16 09:39:26 -080078 uri:
79 url: http://{{ harvester_ip.stdout }}:8954/harvest
80 method: POST
81
82- name: wait for container name resolution
Zack Williamsfe284a12017-07-01 11:00:04 -070083 when: use_maas
Andy Baviera17d84b2016-11-16 09:39:26 -080084 host_dns_check:
85 hosts: "{{ head_lxd_list | map(attribute='name') | list | to_json }}"
86 command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest"
87 register: all_resolved
88 until: all_resolved.everyone == "OK"
89 retries: 5
90 delay: 10
91 failed_when: all_resolved.everyone != "OK"
92
Zack Williams43d62b52017-01-23 07:34:45 -070093- name: Wait for containers to be accessible via SSH
Andy Baviera17d84b2016-11-16 09:39:26 -080094 wait_for:
Zack Williams43d62b52017-01-23 07:34:45 -070095 host: "{{ item.name }}"
96 port: 22
97 search_regex: "OpenSSH"
Andy Baviera17d84b2016-11-16 09:39:26 -080098 with_items: "{{ head_lxd_list }}"
99
Sapan Bhatia35dba662017-04-18 13:32:28 +0200100- name: Ensure /etc/ansible directory exists
Zack Williams5223dd92017-02-28 23:38:02 -0700101 file:
102 path: /etc/ansible
103 state: directory
104 owner: root
105 group: root
106 mode: 0755
Sapan Bhatia35dba662017-04-18 13:32:28 +0200107
Zack Williams5223dd92017-02-28 23:38:02 -0700108- name: Create /etc/ansible/hosts file with containers list
Andy Baviera17d84b2016-11-16 09:39:26 -0800109 template:
Zack Williams5223dd92017-02-28 23:38:02 -0700110 src: ansible_hosts.j2
111 dest: /etc/ansible/hosts
112 owner: root
113 group: root
114 mode: 0644
Andy Baviera17d84b2016-11-16 09:39:26 -0800115