У меня есть следующий инвентарь:
all:
children:
# Declare the front container group
srv0:
hosts:
ocp-prod-srv0:
ansible_host: 123.123.123.123
# Declare the database and file container group
srv1:
hosts:
ocp-prod-srv1:
ansible_host: 192.168.200.3
webapis:
hosts:
ocp-prod-srv2:
ansible_host: 192.168.200.4
# Declare the application container group
webapps:
hosts:
ocp-prod-srv3:
ansible_host: 192.168.200.5
# The app instance on this host will execute the batch
is_worker: true
ocp-prod-srv4:
ansible_host: 192.168.200.6
# The app instance on this host will execute the batch
is_worker: false
# Declare the forge where the webapp binaries are built
jenkins:
hosts:
localhost:
# The proxmox containers. Necessary to configure the proxmox, provision the containers and use as a jump
proxmox_cluster:
hosts:
proxmox:
# IP of the proxmox ** master ** (to manage proxmox clustering)
ansible_host: 141.141.141.141
vars:
# Name of the proxmox node to be used to create the containers
node_name: prxmxsrv1
host_name: 141.141.141.141
# Declaration of network interfaces to use for the environment
proxmox_bridges:
- name: vmbr200
mask: 255.255.255.0
subnet: 192.168.200.0/24
address: 192.168.200.1
subnet_bits: 24
# Define which hosts need to go through the jump to be accessed by Ansible
gatewayed:
hosts:
ocp-prod-srv1:
ocp-prod-srv2:
ocp-prod-srv3:
ocp-prod-srv4:
# Define the configuration parameters of each container (id, name, HD, RAM, inets, etc...)
vm:
hosts:
ocp-prod-srv0:
vm_id: 2002
vm_name: ocp-prod-srv0
netif:
net0:
name: eth0
bridge: vmbr0
ip: 123.123.123.123/32
# Virtual KVM mac adress, configured on provider's IP failover
hwaddr: 52:54:00:00:ba:cc
# Public IP of physical server
gw: 141.141.141.1
net1:
name: eth1
bridge: vmbr200
# The private IP
ip: 192.168.200.2/24
# Max number of cores that can be used
cores: 4
# Max load of the proxmox CPUs (by core % : 2.5 = 2.5 cores)
cpus: 4
diskspace: 10
memory: 2048
ocp-prod-srv1:
vm_id: 2003
vm_name: ocp-prod-srv1
netif:
net0:
name: eth0
bridge: vmbr200
gw: 192.168.200.2
ip: 192.168.200.3/24
# Max number of cores that can be used
cores: 6
# Max load of the proxmox CPUs (by core % : 2.5 = 2.5 cores)
cpus: 4
diskspace: 600
memory: 49152
Я хотел бы получить доступ к названию интерфейса, указанному здесь: "all-> children-> vm-> hosts-> XX-> netif-> YY-> name-> THIS "
Я пробовал десятки кодов, которые я нашел здесь или в другом месте. Никогда не удавалось получить то, что я хотел.
Вот самый «продвинутый» код, который я сделал:
- debug:
msg: "DEBUG : {{ hostvars[item]['netif'] }}"
with_items:
- "{{ groups['vm'] }}"
, который дает мне следующий результат:
TASK [commons/iptables : debug] *******************************************************************************************************************************************************************************************************************************************
ok: [proxmox] => (item=ocp-prod-srv3) => {
"msg": "DEBUG : {u'net0': {u'gw': u'192.168.200.2', u'bridge': u'vmbr200', u'name': u'eth0', u'ip': u'192.168.200.5/24'}}"
}
ok: [proxmox] => (item=ocp-prod-srv0) => {
"msg": "DEBUG : {u'net1': {u'bridge': u'vmbr200', u'name': u'eth1', u'ip': u'192.168.200.2/24'}, u'net0': {u'hwaddr': u'52:54:00:00:ba:cc', u'bridge': u'vmbr0', u'name': u'eth0', u'gw': u'141.141.141.1', u'ip': u'123.123.123.123'}}"
}
ok: [proxmox] => (item=ocp-prod-srv4) => {
"msg": "DEBUG : {u'net0': {u'gw': u'192.168.200.2', u'bridge': u'vmbr200', u'name': u'eth0', u'ip': u'192.168.200.6/24'}}"
}
ok: [proxmox] => (item=ocp-prod-srv1) => {
"msg": "DEBUG : {u'net0': {u'gw': u'192.168.200.2', u'bridge': u'vmbr200', u'name': u'eth0', u'ip': u'192.168.200.3/24'}}"
}
ok: [proxmox] => (item=ocp-prod-srv2) => {
"msg": "DEBUG : {u'net0': {u'gw': u'192.168.200.2', u'bridge': u'vmbr200', u'name': u'eth0', u'ip': u'192.168.200.4/24'}}"
}
Как я могу напечатать «имя» net1 хоста (если он существует)?