Skip to content

Instantly share code, notes, and snippets.

@alimakki
Created January 21, 2018 18:32
Show Gist options
  • Save alimakki/1188a538a2fe19aec9f7c72eb54a5c53 to your computer and use it in GitHub Desktop.
Save alimakki/1188a538a2fe19aec9f7c72eb54a5c53 to your computer and use it in GitHub Desktop.
dev setup snapd
---
- hosts: localhost
gather_facts: no
remote_user: root
become: yes
pre_tasks:
# NOTE(@alimakki): Due to key rotation, we pre-emptivley
# add the Google linux apt signing key required by some
# packages
- name: Install the Google linux apt signing key
shell: "{{ item }}"
with_items:
- "wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -"
- "apt-get clean"
- "apt-get update"
- name:
raw: sudo apt update && apt install python python-apt aptitude -y
- hosts: localhost
gather_facts: yes
remote_user: root
become: yes
tasks:
# If l2tp is enabled we need to build & prepare the Libreswan kernel module
# on the localhost in order for it to be usable by the container
- name: Install Libreswan to support L2TP in container
include_tasks: libreswan-setup.yml
when: streisand_l2tp_enabled
- name: Ensure consistent & clean apt state
shell: "{{ item }}"
with_items:
- "apt-get clean"
- "apt-get update"
- name: Install snapd
apt:
name: snapd
state: present
- name: Install lxd
command: snap install lxd
- name: Create the lxd group
command: addgroup lxd
- name: lxd new group
shell: newgrp lxd
- name: start lxd
command: snap start lxd
- name: ls -ll lxd
shell: ls -ll /var/lib/lxd/unix.socket
register: lxd_dir
- name: debug the contents of the lxd directory
debug:
msg: "{{ lxd_dir.stdout }}"
- name: set permission on lxd daemon
file:
path: /var/snap/lxd/common/lxd/unix.socket
mode: "0777"
- block:
- name: lxd init config
shell: lxd init --auto --storage-backend dir
- name: lxd create network
shell: lxc network create testbr0
- name: lxd attach network to default profile
shell: lxc network attach-profile testbr0 default eth0
ignore_errors: yes
- name: Restart lxd
command: snap restart lxd
- name: pause
pause:
seconds: 10
- name: Retrieve the Ubuntu Xenial AMD64 LXC image fingerprint
uri:
url: https://images.linuxcontainers.org/1.0/images/aliases/ubuntu/xenial/amd64
return_content: yes
register: xenial_fingerprint
- name: Launch streisand container (this will take a while)
lxd_container:
name: streisand
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: lxd
# Use the retrieved alias to fetch the image
alias: "{{ xenial_fingerprint['json']['metadata']['target'] }}"
profiles: ["default"]
config:
security.privileged: "true"
wait_for_ipv4_addresses: true
timeout: 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment