splunk / ansible-role-for-splunk

Splunk@Splunk's Ansible role for installing Splunk, upgrading Splunk, and installing apps/addons on Splunk deployments (VM/bare metal)
Apache License 2.0
146 stars 102 forks source link

configure_shc_captain fails with no attribute #221

Open zyphermonkey opened 7 months ago

zyphermonkey commented 7 months ago

https://github.com/splunk/ansible-role-for-splunk/blob/ad4070802d1e0b643ad047b335ac32caef6f6888/roles/splunk/tasks/configure_shc_captain.yml#L3

I know I used this in the past on our last SHC, but this time it failed with the following error (after taking off no_log). This is possibly an ansible bug because I know we've upgraded the version of ansible on our control node since the last time we built a SHC.

fatal: [splunk-sh-p01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'splunk_mgmt_uri'. 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'splunk_mgmt_uri'\n\nThe error appears to be in '/home/vagrant/.ansible/roles/ansible-role-for-splunk/tasks/configure_shc_captain.yml': line 23, 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- set_fact:\n ^ here\n"}

I solved it by preceding the bootstrap task with the following.

- set_fact:
    splunk_mgmt_uri: "{{ ansible_fqdn }}"

- set_fact:
    splunk_shc_uri_list: "{% for h in groups[splunk_shc_target_group] %}https://{{ hostvars[h].splunk_mgmt_uri }}:{{ splunkd_port }}{% if not loop.last %},{% endif %}{% endfor %}" # If you manage multiple SHCs, configure the var value in group_vars

Looking to start the conversation to see if anyone else can replicate the issue and/or if I should just move forward with a PR.