blob: b27e08ca938de503228f50202a6356782321b063 [file] [log] [blame]
---
# file: create-lxd/tasks/main.yml
- name: Enable trusty-backports apt repository
apt_repository:
repo: "{{ item }}"
state: present
with_items:
- "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse"
- name: Install LXD from trusty-backports
apt:
name: lxd
default_release: trusty-backports
update_cache: yes
cache_valid_time: 3600
- name: Create LXD profiles for OpenStack services
lxd_profile:
name: "openstack-{{ item.name }}"
state: present
config:
user.user-data: |
#cloud-config
ssh_authorized_keys:
- "{{ lookup('file', ssh_pki_dir ~ '/client_certs/{{ pod_sshkey_name }}_sshkey.pub') }}"
description: 'OpenStack service {{ item.name }} for CORD'
devices:
eth0:
type: nic
parent: mgmtbr
nictype: bridged
# ipv4.address: "{{ mgmt_ipv4_first_octets }}.{{ item.ipv4_last_octet }}"
hwaddr: "{{ item.hwaddr | default(hwaddr_prefix ~ ((mgmt_ipv4_first_octets ~ '.' ~ item.ipv4_last_octet) | ip4_hex)) | hwaddr('unix') }}"
certs:
type: disk
path: /usr/local/share/ca-certificates/cord/
source: /usr/local/share/ca-certificates/
with_items: "{{ head_lxd_list }}"
- name: Create containers for the OpenStack services
lxd_container:
name: "{{ item.name }}"
architecture: x86_64
state: started
source:
type: image
mode: pull
server: https://cloud-images.ubuntu.com/releases
protocol: simplestreams
alias: "{{ ansible_distribution_release }}"
profiles: ["openstack-{{ item.name }}"]
wait_for_ipv4_addresses: true
timeout: 600
with_items: "{{ head_lxd_list }}"
- name: fetch IP of DHCP harvester
when: use_maas
command: docker-ip harvester
register: harvester_ip
changed_when: False
- name: force a harvest to get container name resolution
when: use_maas
uri:
url: http://{{ harvester_ip.stdout }}:8954/harvest
method: POST
- name: wait for container name resolution
when: use_maas
host_dns_check:
hosts: "{{ head_lxd_list | map(attribute='name') | list | to_json }}"
command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest"
register: all_resolved
until: all_resolved.everyone == "OK"
retries: 5
delay: 10
failed_when: all_resolved.everyone != "OK"
- name: Wait for containers to be accessible via SSH
wait_for:
host: "{{ item.name }}"
port: 22
search_regex: "OpenSSH"
with_items: "{{ head_lxd_list }}"
- name: Ensure /etc/ansible directory exists
file:
path: /etc/ansible
state: directory
owner: root
group: root
mode: 0755
- name: Create /etc/ansible/hosts file with containers list
template:
src: ansible_hosts.j2
dest: /etc/ansible/hosts
owner: root
group: root
mode: 0644