Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Last active November 7, 2017 19:30
Show Gist options
  • Save hipertracker/240cf208000190b96ee13874e47ca964 to your computer and use it in GitHub Desktop.
Save hipertracker/240cf208000190b96ee13874e47ca964 to your computer and use it in GitHub Desktop.
Ansible - create LXD containers
- hosts: localhost
connection: local
tasks:
- name: Create started inventory containers
lxd_container:
name: "{{ item }}"
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: lxd
alias: ubuntu/xenial/amd64
profiles: ['default']
wait_for_ipv4_addresses: true
timeout: 6000
with_inventory_hostnames:
- all
- name: Add Python 2
delegate_to: "{{ item }}"
raw: test -e /usr/bin/python || (apt update && apt install -y python)
with_inventory_hostnames:
- all
- name: Add authorized keys
delegate_to: "{{ item }}"
authorized_key:
user: root
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
with_inventory_hostnames:
- all
[containers]
web1 ansible_connection=lxd
db1 ansible_connection=lxd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment