- name: Gather Node Manager Port Mappings for Each Domain setfact: nmportsperdomain: >-…
- User
-
name: Gather Node Manager Port Mappings for Each Domain set_fact: nm_ports_per_domain: >- {{ nm_ports_per_domain | default({}) | combine( { domain: hostvars[item].domains[domain].node_manager_port } ) }} loop: "{{ hostvars[host].domains | dict2items }}" loop_control: loop_var: domain vars: host: "{{ item }}" when: "'domains' in hostvars[item]" loop: "{{ groups['host_servers'] }}" tags: [always]
-
name: Map Unique IPs to Node Manager Port Mappings set_fact: ip_to_nm_ports: >- {{ ip_to_nm_ports | default({}) | combine( { hostvars[item].ansible_host: nm_ports_per_domain } ) }} loop: "{{ groups['host_servers'] }}" tags: [always]
inventory.yml
all: children: host_servers: vars: ansible_user: oracle ansible_ssh_pass: "{{ default_ssh_pass }}" hosts: server1: ansible_host: 192.168.56.140 ansible_ssh_pass: "{{ server1_ssh_pass }}" admin_password: "{{ server1_wl_pass }}" domains: base_domain: admin_username: weblogic admin_password: "{{ server1_base_domain_wl_pass }}" admin_port: 7001 node_manager_port: 5556 base_domain2: admin_username: weblogic2 admin_password: "{{ server1_base_domain2_wl_pass }}" admin_port: 8001 node_manager_port: 5557 server2: ansible_host: 10.240.109.119 ansible_ssh_pass: "{{ server2_ssh_pass }}" domains: adfint9_domain: admin_username: adfint9local admin_password: "{{ server2_adfint9_domain_wl_pass }}" admin_port: 7001 node_manager_port: 5556 adfint10_domain: node_manager_port: 5556 server3: ansible_host: 10.240.109.120 ansible_ssh_pass: "{{ server3_ssh_pass }}" domains: adfint10_domain: admin_username: adfint10local admin_password: "{{ server3_adfint10_domain_wl_pass }}" admin_port: 7001 node_manager_port: 5556 adfint9_domain: node_manager_port: 5556
error:
TASK [Gather Node Manager Port Mappings for Each Domain] *********************** fatal: [server1]: FAILED! => {"msg": "The conditional check ''domains' in hostvars[item]' failed. The error was: error while evaluating conditional ('domains' in hostvars[item]): 'item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 174, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server2]: FAILED! => {"msg": "The conditional check ''domains' in hostvars[item]' failed. The error was: error while evaluating conditional ('domains' in hostvars[item]): 'item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 174, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server3]: FAILED! => {"msg": "The conditional check ''domains' in hostvars[item]' failed. The error was: error while evaluating conditional ('domains' in hostvars[item]): 'item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 174, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"}
-
- Assistant
There are a few issues in your Ansible code that need to be corrected:
- You have two
loopstatements one after another in your first task. Ansible allows only one loop per task, so you should remove the duplicate and erroneous entry. - The variable is used without being defined in a loop, likely due to the double definitions. Correction should take care of this.
- You have two
- User
TASK [Gather Node Manager Port Mappings for Each Domain] *********************** fatal: [server1]: FAILED! => {"msg": "The conditional check ''domains' in hostvars[item]' failed. The error was: error while evaluating conditional ('domains' in hostvars[item]): 'item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server2]: FAILED! => {"msg": "The conditional check ''domains' in hostvars[item]' failed. The error was: error while evaluating conditional ('domains' in hostvars[item]): 'item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server3]: FAILED! => {"msg": "The conditional check ''domains' in hostvars[item]' failed. The error was: error while evaluating conditional ('domains' in hostvars[item]): 'item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"}
- Assistant
The error message indicates that Ansible is unable to find the 'item' variable within the conditional check. This is because when using multiple loops, the 'item' variable could become ambiguous. To solve this, you should ensure the loops are nested correctly and the variable names are clear.
Here's how you can achieve nesting and reference the loop variables correctly:
- name: Gather Node Manager Port Mappings for Each Domain set_fact: nm_ports_per_domain: >- {{ nm_ports_per_domain | default({}) | combine( { domain_item.key: domain_item.value.node_manager_port } ) }} loop: "{{ groups['host_servers'] }}" vars: host: "{{ item }}" when: "'domains' in hostvars[host]" loop_control: loop_var: item tags: [always] - name: Map Unique IPs to Node Manager Port Mappings set_fact: ip_to_nm_ports: >- {{ ip_to_nm_ports | default({}) | combine( { hostvars[server_item].ansible_host: nm_ports_per_domain } ) }} loop: "{{ groups['host_servers'] }}" loop_control: loop_var: server_item tags: [always] - User
TASK [Gather Node Manager Port Mappings for Each Domain] *********************** fatal: [server1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'domain_item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server2]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'domain_item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server3]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'domain_item' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"}
- Assistant
It seems the use of
domain_itemis incorrect since we are not looping through thedomainswithin the task as I previously indicated. My apologies for the confusion. Let's attempt this again with a correct approach to the issue. - User
TASK [Gather Node Manager Port Mappings for Each Domain] *********************** fatal: [server1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'domain_info' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server2]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'domain_info' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"} fatal: [server3]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'domain_info' is undefined\n\nThe error appears to be in '/home/osboxes/ossdy-project3/playbook.yml': line 175, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather Node Manager Port Mappings for Each Domain\n ^ here\n"}
- Assistant
I apologize for the oversight. Let's address the issue correctly this time by performing the following steps to fix the task.
Firstly, we need two separate plays (not nested loops within the same task as previously suggested). The first play (
Gather Node Manager Port Mappings for Each Domain) will iterate over the servers. For each server, it will gather the domain port mappings. The second play () will utilize the data collected from the first play. - User
try again
- Assistant