opensearch-project / ansible-playbook

🤖 A community repository for Ansible Playbook of OpenSearch Project.
https://opensearch.org/
Apache License 2.0
81 stars 97 forks source link

[BUG][opensearch]The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'roles' #49

Open patsevanton opened 2 years ago

patsevanton commented 2 years ago

Describe the bug The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'roles'

Run playbook

git clone https://github.com/opensearch-project/ansible-playbook.git opensearch-project
ansible-playbook -vvv -i host.ini opensearch-project/opensearch.yml -b

Inventory

master0 ansible_host=51.250.110.211 ip=192.168.10.5 roles=master,ingest
data0 ansible_host=51.250.103.164 ip=192.168.10.18 roles=data
data1 ansible_host=51.250.103.114 ip=192.168.10.19 roles=data
dashboard0 ansible_host=51.250.100.220 ip=192.168.10.14

[os-cluster]
master0
data0
data1
dashboard0

[master]
master0

[dashboard]
dashboard0

[all:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=~/.ssh/id_rsa
domain_name=opensearch.local
os_download_url=https://artifacts.opensearch.org/releases/bundle/opensearch
os_version=1.3.0
os_user=opensearch
cluster_type=multi-node
os_cluster_name=opensearch
xms_value=8
xmx_value=8

error:

TASK [linux/opensearch : OpenSearch Install | Copy Configuration File]
************************************************************************
fatal: [dashboard0]: FAILED! =>
  msg: |-
    The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'roles'

    The error appears to be in '/home/user/github/infrastructure-as-a-code-example/opensearch-cluster/opensearch-project/roles/linux/opensearch/tasks/opensearch.yml': line 28, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    - name: OpenSearch Install | Copy Configuration File
      ^ here

Version

ansible [core 2.12.2]
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]

Server where ansible

cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"

Remote server

cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
patsevanton commented 2 years ago

@saravanan30erd Could you share inventory and playbook for multiple node setup ? Thanks

saravanan30erd commented 2 years ago

@patsevanton Actually I am using same configuration as it is. https://github.com/opensearch-project/ansible-playbook/blob/main/inventories/opensearch/group_vars/all/all.yml

only change I am doing is, editing the host file for updating the nodes IP address details, thats all. https://github.com/opensearch-project/ansible-playbook/blob/main/inventories/opensearch/hosts

It works fine, you can refer logs here

patsevanton commented 2 years ago

wait merge https://github.com/opensearch-project/ansible-playbook/pull/51 for full test this issue

peterzhuamazon commented 2 years ago

wait merge #51 for full test this issue

Hi @patsevanton that PR is merged now you can test again. Thanks.

patsevanton commented 2 years ago

I tested again and again get this error

Inventory examples don`t have roles https://github.com/opensearch-project/ansible-playbook/blob/main/inventories/opensearch/hosts_centos#L7 https://github.com/opensearch-project/ansible-playbook/blob/main/inventories/opensearch/hosts_ec2-user#L7 https://github.com/opensearch-project/ansible-playbook/blob/main/inventories/opensearch/hosts_root_user#L7 https://github.com/opensearch-project/ansible-playbook/blob/main/inventories/opensearch/hosts_ubuntu#L7

patsevanton commented 2 years ago

But opensearch-multi-node.yml have code:

node.roles: [{{ hostvars[inventory_hostname]['roles'] }}]

In this PR https://github.com/opensearch-project/ansible-playbook/pull/13/files

inventories/opensearch/hosts without dashboard

quiestion: Is dashboard0 requirenment roles or not?

peterzhuamazon commented 2 years ago

But opensearch-multi-node.yml have code:

node.roles: [{{ hostvars[inventory_hostname]['roles'] }}]

In this PR https://github.com/opensearch-project/ansible-playbook/pull/13/files

inventories/opensearch/hosts without dashboard

quiestion: Is dashboard0 requirenment roles or not?

@saravanan30erd

ssi444 commented 2 years ago

@patsevanton remove item "dashboard0" from "[os-cluster]"

[os-cluster]
master0
data0
data1