У меня проблемы с циклическим просмотром списка хостов в группе Ansible, я получаю нужные значения, но получаю ложную ошибку, которую просто не могу выяснить. Если бы произошла ошибка, он бы вообще не печатал значения:
fatal: [worker01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_eth1'\n\nThe error appears to be in 'roles/vagrant/tasks/main.yml': line 15, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n ^ here\n"}
Извлечение из файла vagrant
ansible.groups = {
"workers" => ["worker01", "worker02", "worker03"],
"controllers" => ["controller01", "controller02"],
"kubernetes" => ["kubernetes"],
"all_groups:children" => ["workers", "controllers", "kubernetes"]
}
Пример определения хоста, используемого vagrant
{
"name": "worker03",
"alias": "worker03",
"box": "bento/ubuntu-18.04",
"memory": 2048,
"vcpu": 2,
"provider": "virtualbox",
"autostart": "false",
"cpus": 2,
"cpu_percentage": 100,
"Controller": "SATA Controller",
"lv_disks": 4,
"pv_size": 5,
"infra_ip_addr": "10.2.15.60",
"service_ip_addr": "10.96.0.60",
"pod_ip_addr": "192.168.0.60",
"port_forwards": {},
"project": "wks",
"tags": "all",
"group": "workers",
"extra_vars": {}
}
Следующий код:
- debug:
msg: "External: {{ hostvars[item]['ansible_eth1']['ipv4']['address'] }} ; Service: {{ hostvars[inventory_hostname]['ansible_eth3']['ipv4']['address'] }} "
with_items:
- "{{ groups['workers'] }}"
Производит вывод - ошибка примечания 'объект ansible.vars.hostvars.HostVarsVars' не имеет атрибута ansible_eth1 '
ok: [worker01] => (item=worker01) => {
"msg": "External: 10.2.15.40 ; Service: 192.168.0.40 "
}
fatal: [worker01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_eth1'\n\nThe error appears to be in 'roles/vagrant/tasks/main.yml': line 15, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n ^ here\n"}
PLAY RECAP ****************************************************************************************************************************************************************************************************************************
worker01 : ok=3 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0