# Goal: When playbook / task is called.. use varibles set for specific host withing a group
/hosts.yml # site wide master ansible inentory
all:
children:
###### Physical HyperConverge Server Devices for environment ###########
hci_hosts: # Nodes for hosting VMs
hosts:
thor:
vars:
mgmt_nic: enp8s0f0 # Set in Kickstart OS install
storage_nic: ens15f0
ovs_nic: enp8s0f1
ovirt_disk: ata-Samsung_SSD_850_PRO_512GB_S250NXAGA15787L # ls -al /dev/disk/by-id/ |grep sdb
data00_disk: ata-WDC_WDS100T2B0B-00YS70_192490801828 # ls -al /dev/disk/by-id/ |grep sdc
data01_disk: ata-WDC_WDS100T2B0B-00YS70_19106A802926 # ls -al /dev/disk/by-id/ |grep sdd
odin:
vars:
mgmt_nic: enp8s0f0 # Set in Kickstart OS install
storage_nic: ens15f0
ovirt_disk: ata-Micron_1100_MTFDDAV512TBN_17401F699137 # ls -al /dev/disk/by-id/ |grep sdb
data00_disk: ata-WDC_WDS100T2B0B-00YS70_183533804564 # ls -al /dev/disk/by-id/ |grep sdc
data01_disk: nvme-nvme.126f-4141303030303030303030303030303032343538-53504343204d2e32205043496520535344-00000001 # ls -al /dev/disk/by-id/ |grep nvme0n1
<snip>...
#### Task: setup host networking and disk.. where each host is different .. so have to set individulized varibles
---
# Configuration of unified /etc/hosts file for nodes
# v0.002 20210131
# file: /roles/role_network_hosts.yml
# <<<<<<<<<DRAFT>>>>>>>>>>>
- name: Copy a version of hosts file common for nodes to ignite cluster
ansible.builtin.copy:
src: hosts_ignition_template
dest: /etc/hosts
group: root
setype: named_conf_t
mode: 0644
### Test varible and precidence order
- debug:
msg: "{{ inventory_hostname }} this should be hostname response of thor"
- debug:
msg: "{{ ansible_default_ipv4.gateway }} this should be gateway this shoudld be response of 172.16.100.1"
- debug:
msg: "{{ inventory_hostname[storage_nic] }} this should be NIC of thor for storage"
- debug:
msg: "{{ storage_nic }} this should be NIC of thor for storage"
- debug:
msg: "{{ ovirt_disk }} this likely will fail as it should be host ovirtdisk"
############### Test output
$ ansible-playbook hci_deploy.yml --limit thor
PLAY [Ansible Pinging Host which validates SSH passwordless login] *******************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************************ok: [thor]
TASK [hci_cluster : Copy a version of hosts file common for nodes to ignite cluster] *************************************************************************************ok: [thor]
TASK [hci_cluster : debug] ***********************************************************************************************************************************************ok: [thor] =>
msg: thor this should be hostname response of thor
TASK [hci_cluster : debug] ***********************************************************************************************************************************************ok: [thor] =>
msg: 172.16.100.1 this should be gateway this shoudld be response of 172.16.100.1
TASK [hci_cluster : debug] ***********************************************************************************************************************************************fatal: [thor]: FAILED! =>
msg: |-
The task includes an option with an undefined variable. The error was: ansible.parsing.yaml.objects.AnsibleUnicode object has no element AnsibleUndefined
The error appears to be in '/mnt/c/GitHub/penguinpages_cluster_devops/cluster_devops/roles/task_network_hosts.yml': line 43, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- debug:
^ here
PLAY RECAP ***************************************************************************************************************************************************************thor : ok=4 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
#######################
Summary: any variable caleld which is "nested" does not work.
Question: How can I use a "host variable" nested. so when I call a playbook for a group, each host specific task can use common variables within sub routines
--