Добавил ssh в ansible-base и стырил плейбук для создания LXD контейнеров

This commit is contained in:
2021-11-06 02:31:50 +00:00
parent cc48cb444c
commit 8b1ac8796f
8 changed files with 225 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
Создает контейнеры из указанного inventory с указанными в нем же IPшниками
Source: https://dev.to/livioribeiro/using-lxd-and-ansible-to-simulate-infrastructure-2g8l

View File

@@ -0,0 +1,3 @@
# ansible.cfg
[defaults]
inventory = inventory

View File

@@ -0,0 +1,16 @@
# inventory/hosts
[centos]
centos1 ip_address=10.222.43.101
centos2 ip_address=10.222.43.102
centos3 ip_address=10.222.43.103
[ubuntu]
ubuntu1 ip_address=10.222.43.111
ubuntu2 ip_address=10.222.43.112
ubuntu3 ip_address=10.222.43.113
[all:vars]
ansible_connection=lxd
ansible_python_interpreter=/usr/bin/python3

View File

@@ -0,0 +1,62 @@
---
- 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