Ansible mit lxc inventory Template

This commit is contained in:
Michael Schaar 2023-09-26 12:17:33 +02:00
parent 7ca0aafbbc
commit 8bf70e0824
6 changed files with 70 additions and 0 deletions

BIN
AIS/.lxc-create.yml.swp Normal file

Binary file not shown.

2
AIS/ansible.cfg Normal file
View File

@ -0,0 +1,2 @@
[defaults]
inventory = ./inventory

12
AIS/inventory Normal file
View File

@ -0,0 +1,12 @@
[lokal]
localhost ansible_connection=local
[ais]
debian ansible_host=10.0.3.123
suse ansible_host=10.0.3.187
rocky ansible_host=10.0.3.114
ubuntu ansible_host=10.0.3.250
[ais:vars]
ansible_user=ubuntu
ansible_password=ubuntu

12
AIS/inventory.lxc Normal file
View File

@ -0,0 +1,12 @@
[lokal]
localhost ansible_connection=local
[notme]
10.0.3.110 ansible_user=ubuntu ansible_password=ubuntu
10.0.3.55 ansible_user=ubuntu ansible_password=ubuntu
[ais]
debian ansible_host=10.0.3.123
suse ansible_host=10.0.3.187
rocky ansible_host=10.0.3.114
ubuntu ansible_host=10.0.3.250

33
AIS/lxc-create.yml Normal file
View File

@ -0,0 +1,33 @@
---
- hosts: lokal
become: yes
vars:
lxc_names:
- debian
- suse
- rocky
- ubuntu
tasks:
- name: Create a started container
community.general.lxc_container:
name: "{{ item }}"
container_log: true
template: ubuntu
state: started
template_options: --release focal
#container_command: |
# hostname -I
with_items: "{{ lxc_names }}"
register: lvm_container_info
- name: Variable ausgeben
debug:
msg: "Der Container {{ item.item }} hat {{ item.lxc_container.ips[0] }}"
with_items: "{{ lvm_container_info.results }}"
- name: Create inventory
template:
src: inventory.j2
dest: inventory

View File

@ -0,0 +1,11 @@
[lokal]
localhost ansible_connection=local
[ais]
{% for container in lvm_container_info.results %}
{{ container.item }} ansible_host={{ container.lxc_container.ips[0] }}
{% endfor %}
[ais:vars]
ansible_user=ubuntu
ansible_password=ubuntu