Ansible mit lxc inventory Template
This commit is contained in:
parent
7ca0aafbbc
commit
8bf70e0824
Binary file not shown.
|
@ -0,0 +1,2 @@
|
|||
[defaults]
|
||||
inventory = ./inventory
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue