devops-shit/ansible/lxc-create-multiple/playbook.yml

63 lines
2.4 KiB
YAML

---
- hosts: localhost
# run this task in the host
connection: local
tasks:
- name: create containers cent
# get all host names from inventory
loop: "{{ groups['centos'] }}"
# use lxd_container module from ansible to create containers
lxd_container:
# container name is the hostname
name: "{{ item }}"
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: simplestreams
alias: centos/8-Stream/cloud
config:
# nomad clients need some privileges to be able to run docker containers
security.nesting: "{{ 'true' if item in ['nomad-client1', 'nomad-client2', 'nomad-client3'] else 'false' }}"
security.privileged: "{{ 'true' if item in ['nomad-client1', 'nomad-client2', 'nomad-client3'] else 'false' }}"
devices:
# configure network interface
eth0:
type: nic
nictype: bridged
parent: lxdbr0
# get ip address from inventory
ipv4.address: "{{ hostvars[item].ip_address }}"
# # uncomment if you installed lxd using snap
# url: unix:/var/snap/lxd/common/lxd/unix.socket
- name: create containers ubuntu
# get all host names from inventory
loop: "{{ groups['ubuntu'] }}"
# use lxd_container module from ansible to create containers
lxd_container:
# container name is the hostname
name: "{{ item }}"
state: started
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: simplestreams
alias: ubuntu/bionic/amd64
config:
# nomad clients need some privileges to be able to run docker containers
security.nesting: "{{ 'true' if item in ['nomad-client1', 'nomad-client2', 'nomad-client3'] else 'false' }}"
security.privileged: "{{ 'true' if item in ['nomad-client1', 'nomad-client2', 'nomad-client3'] else 'false' }}"
devices:
# configure network interface
eth0:
type: nic
nictype: bridged
parent: lxdbr0
# get ip address from inventory
ipv4.address: "{{ hostvars[item].ip_address }}"
# # uncomment if you installed lxd using snap
# url: unix:/var/snap/lxd/common/lxd/unix.socket