hispanico.lxd
Ansible-LXD
This role helps you manage LXD Profiles and Containers on a remote LXD Server. More info at: https://linuxcontainers.org/lxd/
Requirements
- You need LXD version 2.0 or higher installed on both the LXD host and the Ansible server (it's usually included by default on Ubuntu 16.04).
- Set up LXD on the remote host with the command:
sudo lxd init
. - Before using Ansible to manage the LXD host remotely, run these commands:
On the remote LXD host:
$ lxc config set core.https_address [::]:8443
$ lxc config set core.trust_password replace-this-with-a-secure-password
On the Ansible host:
$ lxc config set core.https_address [::]:8443
$ lxc remote add lxd4 lxd4.example.com
(Replace lxd4.example.com
with your LXD host's hostname; you can name lxd4
whatever you want, but you'll need to use this name in the inventory file).
- This has been tested on both LXD and Ansible hosts running Ubuntu 16.04 LTS, and may work with other distributions.
Role Variables
LXD Profile Variables:
url:
unix:/var/snap/lxd/common/lxd/unix.socket (default)state:
present (default), absent
LXD Container Variables:
url:
unix:/var/snap/lxd/common/lxd/unix.socket (default)state:
started (default), stopped, restarted, absent, frozentype:
image (default)mode:
pull (default)server:
https://cloud-images.ubuntu.com/releases (default)protocol:
simplestreams (default)alias:
"16.04" (default)architecture:
x86_64 (default)wait_for_ipv4_addresses:
true (default)timeout:
600 (default)
For more details, check:
Additional Variables:
cloud_init:
cloud-init configuration (cloud-init documentation)
Default Values:
# LXD Profiles
lxd_profiles:
- name: default
description: "Default LXD Profile"
status: present
# LXD Containers
LXCs:
- name: mycontainer
mode: pull
server: https://cloud-images.ubuntu.com/releases
alias: "16.04"
protocol: simplestreams
architecture: x86_64
profile: default
status: started
Dependencies
- None
Example
The following example sets up a default LXD profile with a cloud-init option to install Python packages and create an Ansible user. It will then install 2 containers on the LXD server.
- hosts: all
roles:
- ansible-lxd
vars:
lxd_profiles:
- name: default
description: "Default LXD Profile"
storage_pool: default
network: lxdbr0
cloud_init: |
#cloud-config
packages:
- python
users:
- name: ansible
group: sudo
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- {{ lookup('file', '$HOME/.ssh/id_rsa.pub' ) }}
status: present
LXCs:
- name: MyContainer01
mode: pull
server: https://cloud-images.ubuntu.com/releases
alias: "16.04"
protocol: simplestreams
architecture: x86_64
disk_space: 50GB # Disk limit for the container
memory: 2GB # Memory limit for the container
storage_pool: default
network: lxdbr0
ipv4address: 10.0.0.2 # Static IPv4 address for lxdbr0 subnet
profile: default
status: started
- name: MyContainer02
mode: pull
server: https://cloud-images.ubuntu.com/releases
alias: "16.04"
protocol: simplestreams
architecture: x86_64
disk_space: 50GB # Disk limit for the container
memory: 2GB # Memory limit for the container
nesting: "true" # Enable container's security.nesting
storage_pool: default
network: lxdbr0
ipv4address: 10.0.0.3 # Static IPv4 address for lxdbr0 subnet
profile: default
status: started
License
Licensed under the GPLv3 License. See the LICENSE file for details.
Author Information
Hispanico
Informazioni sul progetto
Manage LXD Profile and LXD Containers
Installa
ansible-galaxy install hispanico.lxd
Licenza
gpl-3.0
Download
357
Proprietario
@openwisp Contributor and @ninuxorg Member