blob: 3e081a2011fdcba6d33c69947e6e4237a0e24d7f [file] [log] [blame]
Andy Baviera17d84b2016-11-16 09:39:26 -08001---
2# file: create-lxd/tasks/main.yml
3- name: Ensure DIG
4 become: yes
5 apt:
6 name: dnsutils=1:9*
7 state: present
8
9- name: Enable trusty-backports
10 become: yes
11 apt_repository:
12 repo: "{{ item }}"
13 state: present
14 with_items:
15 - "deb http://us.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe"
16 - "deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe"
17
18- name: Ensure LXD
19 become: yes
20 apt:
21 name: lxd
22 state: present
23 update_cache: yes
24 default_release: trusty-backports
25
Zack Williams43d62b52017-01-23 07:34:45 -070026# For lxd_profile, has to be run as normal user
27- name: Get user's SSH public key into lxd_ssh_pubkey to create LXD profile
28 set_fact:
29 lxd_ssh_pubkey: "{{ lookup('file', '{{ ansible_user_dir }}/.ssh/id_rsa.pub') }}"
Andy Baviera17d84b2016-11-16 09:39:26 -080030
31- name: Create openstack LXD profile
32 become: yes
33 lxd_profile:
34 name: openstack
35 state: present
36 config:
37 user.user-data: |
38 #cloud-config
39 ssh_authorized_keys:
Zack Williams43d62b52017-01-23 07:34:45 -070040 - "{{ lxd_ssh_pubkey }}"
Andy Baviera17d84b2016-11-16 09:39:26 -080041 description: 'OpenStack services on CORD'
42 devices:
43 eth0:
44 nictype: bridged
45 parent: mgmtbr
46 type: nic
47
48- name: Create containers for the OpenStack services
49 become: yes
50 lxd_container:
51 name: "{{ item.name }}"
52 architecture: x86_64
53 state: started
54 source:
55 type: image
56 mode: pull
57 server: https://cloud-images.ubuntu.com/releases
58 protocol: simplestreams
59 alias: "{{ ansible_distribution_release }}"
60 profiles: ["openstack"]
61 wait_for_ipv4_addresses: true
62 timeout: 600
63 with_items: "{{ head_lxd_list }}"
64
65- name: fetch IP of DHCP harvester
66 when: on_maas
67 command: docker-ip harvester
68 register: harvester_ip
69 changed_when: False
70
71- name: force a harvest to get container name resolution
72 when: on_maas
73 uri:
74 url: http://{{ harvester_ip.stdout }}:8954/harvest
75 method: POST
76
77- name: wait for container name resolution
78 when: on_maas
79 host_dns_check:
80 hosts: "{{ head_lxd_list | map(attribute='name') | list | to_json }}"
81 command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest"
82 register: all_resolved
83 until: all_resolved.everyone == "OK"
84 retries: 5
85 delay: 10
86 failed_when: all_resolved.everyone != "OK"
87
Zack Williams43d62b52017-01-23 07:34:45 -070088- name: Wait for containers to be accessible via SSH
Andy Baviera17d84b2016-11-16 09:39:26 -080089 wait_for:
Zack Williams43d62b52017-01-23 07:34:45 -070090 host: "{{ item.name }}"
91 port: 22
92 search_regex: "OpenSSH"
Andy Baviera17d84b2016-11-16 09:39:26 -080093 with_items: "{{ head_lxd_list }}"
94
95- name: Create /etc/ansible/hosts file
96 become: yes
97 template:
98 src=ansible_hosts.j2
99 dest=/etc/ansible/hosts
100
101- name: Verify that we can log into every container
102 command: ansible containers -m ping -u ubuntu
103 tags:
104 - skip_ansible_lint # connectivity check
105
Andy Bavier03363372017-02-23 14:57:34 -0500106- name: Verify that containers have external connectivity
107 command: ansible containers -m uri -u ubuntu -a "url=http://www.google.com"
108 tags:
109 - skip_ansible_lint # connectivity check
110
Andy Baviera17d84b2016-11-16 09:39:26 -0800111- name: Have containers use the apt-cache
112 command: ansible containers -b -u ubuntu -m lineinfile -a "dest=/etc/apt/apt.conf.d/02apt-cacher-ng create=yes mode=0644 owner=root group=root regexp='^Acquire' line='Acquire::http { Proxy \"http://{{ apt_cacher_name }}:{{ apt_cacher_port | default('3142') }}\"; };'"
113 tags:
114 - skip_ansible_lint # running a sub job
115
116- name: Update apt cache
117 command: ansible containers -m apt -b -u ubuntu -a "update_cache=yes cache_valid_time=3600"
118 tags:
119 - skip_ansible_lint # running a sub job
120
121- name: Update software in all the containers
122 when: run_dist_upgrade
123 command: ansible containers -m apt -b -u ubuntu -a "upgrade=dist"
124 tags:
125 - skip_ansible_lint # running a sub job
126
127- name: Create containers' eth0 interface config file for DNS config via resolvconf program
128 when: not on_maas
129 template:
130 src=eth0.cfg.j2
131 dest={{ ansible_user_dir }}/eth0.cfg
132
133- name: Copy eth0 interface config file to all containers
134 when: not on_maas
135 command: ansible containers -b -u ubuntu -m copy -a "src={{ ansible_user_dir }}/eth0.cfg dest=/etc/network/interfaces.d/eth0.cfg owner=root group=root mode=0644"
136
137- name: Restart eth0 interface on all containers
138 when: not on_maas
139 command: ansible containers -b -u ubuntu -m shell -a "ifdown eth0 ; ifup eth0"
140
141- name: Verify that we can log into every container after restarting network interfaces
142 when: not on_maas
143 command: ansible containers -m ping -u ubuntu