Skip to content

Commit

Permalink
Updates for lxd 3.0 with snap (#1)
Browse files Browse the repository at this point in the history
* Some code updates

*  New path to unix.socket

* Code yaml corrected

* Add item.url

* Install lxd only from snap

* Inventory update

* Disable security apparmor for nested containers

* Spell correct

* Add dependencies

* Inventory updates

Inventory localhost

No zfs for trusy

Default pool driver to dir

Default driver conditional

Pre task

Correct code

State absent

Add user travis

Create lxd group and add user to it

Xenial on travis

Install zfsutils

zfsutils-linux

List var/snap directory

Ls var

lxd init --auto

Lxd configuration only

Install lxd in travis

Install with sudo

Correct conditional

Restart lxd service

Install lxd from role

Restart services

Start lxd service

Masked no

Restart snap.lxd.daemon

Snap.lxc restarted

Install lxd only if not available

Lxd conditional
  • Loading branch information
basilgood authored and megheaiulian committed Jul 24, 2018
1 parent d5efe2d commit 7018824
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---

dist: xenial
sudo: required
language: python
python:
- "2.7"
script:
- sudo pip install ansible
- sudo snap install lxd
- sudo ansible-playbook -i tests/inventory -vvvv tests/test.yml
- >
sudo ansible-playbook -i tests/inventory -vvvv tests/test.yml
Expand Down
1 change: 0 additions & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
remote_tmp = /tmp/.ansible-${USER}/tmp
local_tmp = $HOME/.ansible/tmp
pipelining=True

19 changes: 10 additions & 9 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
---
lxd_apt_stable_repo: yes
lxd_packages:
- lxd
- zfsutils-linux

lxd_install: true

lxd_default_url: unix:/var/snap/lxd/common/lxd/unix.socket

lxd_users: []

lxd_init: yes
lxd_init: true

#lxc init: default pool
# lxc init: default pool
lxd_default_pool_size: 39GB
lxd_default_pool_driver: zfs
lxd_default_pool_zfs_acl: 'off' #posixacl, noacl, off
lxd_default_pool_zfs_acl: 'off' # posixacl, noacl, off
lxd_default_pool_config:
size: '{{ lxd_default_pool_size }}'
source: /var/lib/lxd/disks/default.img
zfs.pool_name: default

#lxd init: default bridge
# lxd init: default bridge
lxd_default_bridge_ipv4_address: 'auto'
lxd_default_bridge_config:
ipv4.nat: 'true'
Expand Down Expand Up @@ -48,4 +49,4 @@ lxd_config:
# Add DNS servers to dhcp
lxd_prepend_dns: []

lxd_containters: []
lxd_containers: []
6 changes: 6 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
service:
name: networking
state: restarted

- name: restart lxd
systemd:
name: lxd
state: restarted
daemon-reload: true
10 changes: 6 additions & 4 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---

- name: Deploy LXD preseed
template: src="{{ lxd_config_preseed }}" dest="/tmp/lxd.preseed"
when: lxd_init|default(False)
template:
src: "{{ lxd_config_preseed }}"
dest: "/tmp/lxd.preseed"
when: lxd_init|default(false)
register: lxd_preseed_status

- name: Configure LXD
Expand All @@ -14,15 +16,15 @@
- name: Add LXD DNS to dhcp
blockinfile:
dest: /etc/dhcp/dhclient.conf
backup: yes
backup: true
block: 'prepend domain-name-servers {{ item }};'
marker: '#{mark} LXD DNS'
with_items: '{{ lxd_prepend_dns }}'
notify: restart networking

- name: Get acl status for default pool
shell: zfs get acltype default | grep default | awk '{print $3}'
when: lxd_default_pool_driver == 'zfs' and lxd_init|default(False)
when: lxd_default_pool_driver == 'zfs' and lxd_init|default(false)
register: lxd_zfs_acl_status
changed_when: lxd_zfs_acl_status.stdout != lxd_default_pool_zfs_acl

Expand Down
1 change: 1 addition & 0 deletions tasks/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
config: '{{ item.config | default(omit) }}'
wait_for_ipv4_addresses: '{{ item.wait_for_ipv4_addresses | default(omit)}}'
devices: '{{ item.devices | default(omit) }}'
url: '{{ item.url| default(lxd_default_url) }}'
become: '{{ item.become | default(omit) }}'
become_method: '{{ item.become_method | default(omit) }}'
become_flags: '{{ item.become_flags | default(omit) }}'
Expand Down
10 changes: 10 additions & 0 deletions tasks/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

- name: Install dependencies
apt:
name: '{{ item }}'
update_cache: true
with_items:
- software-properties-common
- snapd
- zfsutils-linux
30 changes: 23 additions & 7 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
---
- name: Ensure APT LXD repository (stable)
apt_repository: repo='ppa:ubuntu-lxc/lxd-stable' update_cache='yes'
when: lxd_apt_stable_repo

- name: Install LXD
package: name={{ item }} state=present
with_items: '{{ lxd_packages }}'
- name: Ensure there is no lxd installed from repo
apt:
name: '{{ item }}'
state: absent
with_items:
- lxd
- lxd-client

- name: Create lxd group
group:
name: lxd
state: present

- name: Add users to lxd group
user: name={{ item }} groups=lxd append=yes
user:
name: '{{ item }}'
groups: lxd
append: true
with_items: '{{ lxd_users }}'
register: lxd_group_users_status

- name: Install LXD with snap
shell: snap install {{ item }}
with_items:
- lxd --channel=3.0
when: lxd_install == "true"
changed_when: false
9 changes: 6 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---

- include: install.yml
- import_tasks: dependencies.yml
tags: [lxd, lxd-install]

- include: configure.yml
- import_tasks: install.yml
tags: [lxd, lxd-install]

- import_tasks: configure.yml
tags: [lxd, lxd-configure]

- include: containers.yml
- import_tasks: containers.yml
tags: [lxd, lxd-containers]
1 change: 1 addition & 0 deletions tests/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Vagrant.configure("2") do |config|

config.vm.provision 'ansible' do |ansible|
ansible.playbook = 'test.yml'
ansible.extra_vars = { ansible_python_interpreter: '/usr/bin/python3' }
end
end

7 changes: 7 additions & 0 deletions tests/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

security.nesting=true
security.privileged=true
raw.lxc: |-
lxc.apparmor.profile=unconfined
lxc.cgroup.devices.allow=a
1 change: 1 addition & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
localhost ansible_connection=local
# lxc-test ansible_connection=lxd ansible_python_interpreter='/usr/bin/python3'
20 changes: 16 additions & 4 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
---

- hosts: localhost
become: True
- hosts: all
become: true
roles:
- role: plumelo.lxd
lxd_packages: ['lxd']
lxd_install: false
lxd_users: ['travis']
lxd_dns_ipv4: '10.229.31.1'
lxd_prepend_dns: ['{{ lxd_dns_ipv4 }}']
lxd_default_bridge_ipv4_address: '{{ lxd_dns_ipv4 }}/24'
lxd_default_pool_driver: dir
lxd_default_pool_config: {}
cloud_config:
package_upgrade: true
manage_etc_hosts: true
hostname: xenial
packages:
- python
- acl
- sudo
lxd_user_data: "#cloud-config\n{{ cloud_config|to_yaml(indent=2) }}"
lxd_containers:
- name: xenial
state: started
become_user: travis
alias: 'x'
config:
user.user-data: "#cloud-config\n{{ cloud_config|combine({'hostname': 'xenial'})|to_yaml(indent=2) }}"
security.nesting: 'true'
security.privileged: 'true'
user.user-data: "{{lxd_user_data}}"
devices: {}
timeout: 600

# lxc_config:
# security.nesting=true
# security.privileged=true
# raw.lxc: |-
# lxc.apparmor.profile=unconfined
# lxc.cgroup.devices.allow=a

0 comments on commit 7018824

Please sign in to comment.