Closed animeshgupta720 closed 3 years ago
Hello @animeshgupta720
As per your output, it seems you are using CVaas approach. Could you share variables you are using to authenticate against CVaas as well as playbook you are running ?
Regards,
Hi @titom73
I am working with @animeshgupta720 on this code. Please find the snippet below.
sshaurya@C02Z91Z8LVCH cvp_test -> cat ansible.cfg
[defaults]
host_key_checking = False
gathering = explicit
retry_files_enabled = False
collections_paths = /Users/sshaurya/Documents/ansible-cvp
sshaurya@C02Z91Z8LVCH cvp_test -> cat hosts
[cvp]
www.arista.io
[cvp:vars]
ansible_host=www.arista.io
ansible_python_interpreter=/usr/local/bin/python3
ansible_user=cvaas # Shall not be changed. ansible will switch to cvaas mode
ansible_ssh_pass=<omitted for safety>
ansible_connection=httpapi
ansible_network_os=eos
ansible_become=true
ansible_become_method=enable
ansible_httpapi_port=443
ansible_httpapi_host=www.arista.io
ansible_httpapi_use_ssl=true
ansible_httpapi_validate_certs=false
sshaurya@C02Z91Z8LVCH cvp_test -> cat main.yaml
---
- name: Playbook to demonstrate cv_container module.
hosts: cvp
connection: local
gather_facts: no
collections:
- arista.cvp
tasks:
- name: "Gather CVP facts"
cv_facts:
register: cvp_facts
Thanks.
Could you update arista.cvp to latest version (2.1.2) and cvprac in version 1.0.5
$ pip install --upgrade cvprac>=1.0.5
$ ansible-galaxy collection install --force arista.cvp:==2.1.2
Hi @titom73
Thanks for your prompt response. I still see the same error.
sshaurya@C02Z91Z8LVCH cvp_test -> pip install --upgrade cvprac>=1.0.5
sshaurya@C02Z91Z8LVCH cvp_test -> ansible-galaxy collection install --force arista.cvp:==2.1.2
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Installing 'arista.cvp:2.1.2' to '/Users/sshaurya/Documents/ansible-cvp/ansible_collections/arista/cvp'
Downloading https://galaxy.ansible.com/download/arista-cvp-2.1.2.tar.gz to /Users/sshaurya/.ansible/tmp/ansible-local-62295qvnnpnn0/tmpjy4hk5g1
arista.cvp (2.1.2) was installed successfully
sshaurya@C02Z91Z8LVCH cvp_test -> ansible-playbook -i hosts main.yaml -vvv
ansible-playbook 2.10.7
config file = /Users/sshaurya/Downloads/cvp_test/ansible.cfg
configured module search path = ['/Users/sshaurya/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.9.1 (default, Dec 17 2020, 03:41:37) [Clang 12.0.0 (clang-1200.0.32.27)]
Using /Users/sshaurya/Downloads/cvp_test/ansible.cfg as config file
host_list declined parsing /Users/sshaurya/Downloads/cvp_test/hosts as it did not pass its verify_file() method
auto declined parsing /Users/sshaurya/Downloads/cvp_test/hosts as it did not pass its verify_file() method
Parsed /Users/sshaurya/Downloads/cvp_test/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: main.yaml *******************************************************************************************************
1 plays in main.yaml
PLAY [Playbook to demonstrate cv_container module.] ***********************************************************************
META: ran handlers
TASK [Gather CVP facts] ***************************************************************************************************
task path: /Users/sshaurya/Downloads/cvp_test/main.yaml:9
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
redirecting (type: httpapi) ansible.builtin.eos to arista.eos.eos
redirecting (type: become) ansible.builtin.enable to ansible.netcommon.enable
<www.arista.io> ESTABLISH LOCAL CONNECTION FOR USER: sshaurya
<www.arista.io> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj `"&& mkdir "` echo /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/ansible-tmp-1618516712.2056131-62322-280486793473490 `" && echo ansible-tmp-1618516712.2056131-62322-280486793473490="` echo /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/ansible-tmp-1618516712.2056131-62322-280486793473490 `" ) && sleep 0'
Using module file /Users/sshaurya/Documents/ansible-cvp/ansible_collections/arista/cvp/plugins/modules/cv_facts.py
<www.arista.io> PUT /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/tmpljhex7l9 TO /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/ansible-tmp-1618516712.2056131-62322-280486793473490/AnsiballZ_cv_facts.py
<www.arista.io> EXEC /bin/sh -c 'chmod u+x /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/ansible-tmp-1618516712.2056131-62322-280486793473490/ /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/ansible-tmp-1618516712.2056131-62322-280486793473490/AnsiballZ_cv_facts.py && sleep 0'
<www.arista.io> EXEC /bin/sh -c '/usr/local/bin/python3 /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/ansible-tmp-1618516712.2056131-62322-280486793473490/AnsiballZ_cv_facts.py && sleep 0'
<www.arista.io> EXEC /bin/sh -c 'rm -f -r /Users/sshaurya/.ansible/tmp/ansible-local-62318h2p526xj/ansible-tmp-1618516712.2056131-62322-280486793473490/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
File "/var/folders/36/dnqwqbw97pzg6xbrx45pr2vm0000gp/T/ansible_cv_facts_payload_pjnkv4ju/ansible_cv_facts_payload.zip/ansible_collections/arista/cvp/plugins/module_utils/tools_cv.py", line 79, in cv_connect
client.connect(nodes=[host],
File "/usr/local/lib/python3.9/site-packages/cvprac/cvp_client.py", line 327, in connect
raise CvpLoginError(self.error_msg)
fatal: [www.arista.io]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"facts": [
"all"
],
"gather_subset": [
"default"
]
}
},
"msg": "\nwww.arista.io: Authenticate: https://www.arista.io:443/web/login/authenticate.do: Request Error: Not Found - <html>\r\n<head><title>404 Not Found</title></head>\r\n<body>\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/1.16.0</center>\r\n</body>\r\n</html>\r\n\n"
}
PLAY RECAP ****************************************************************************************************************
www.arista.io : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
sshaurya@C02Z91Z8LVCH cvp_test ->
@titom73 Did you get some time to look into this issue?
I have looked over cvprac project code and we can see this authentication is not the correct one and has been changed in this commit https://github.com/aristanetworks/cvprac/commit/409b68d905850bd471b0355b2574cf4497579ada part of v1.0.5
Could you share result of pip freeze
?
Thanks @titom73 . Please find the output below.
sshaurya@C02Z91Z8LVCH cvp_test -> pip freeze
altgraph==0.17
ansible==3.1.0
ansible-base==2.10.7
appdirs==1.4.4
asgiref==3.3.1
atomicwrites==1.4.0
attrs==20.3.0
bcrypt==3.2.0
boto3==1.17.14
botocore==1.20.14
cachetools==4.1.1
certifi==2020.11.8
cffi==1.14.3
chardet==3.0.4
constants==0.6.0
cryptography==3.2.1
cvprac==1.0.5
defusedxml==0.7.1
diskcache==5.1.0
distlib==0.3.1
Django==3.1.7
dnacentersdk==2.0.2
ecdsa==0.16.1
fastjsonschema==2.15.0
filelock==3.0.12
fpyutils==1.2.2
future==0.18.2
google-api-core==1.23.0
google-api-python-client==1.12.5
google-auth==1.27.0
google-auth-httplib2==0.0.4
google-auth-oauthlib==0.4.2
google-cloud-core==1.6.0
google-cloud-storage==1.36.1
google-crc32c==1.1.2
google-resumable-media==1.2.0
googleapis-common-protos==1.52.0
gpg==1.15.0
grpcio==1.36.1
gspread==3.6.0
gspread-formatting==0.3.4
httplib2==0.18.1
idna==2.10
ipaddress==1.0.23
Jinja2==2.11.3
jira==2.0.0
jmespath==0.10.0
json-rpc==1.13.0
jsonschema==3.2.0
lca==1.8.271
macholib==1.14
MarkupSafe==1.1.1
md-toc==7.1.0
modulegraph==0.18
mysql-connector==2.2.9
netaddr==0.7.19
netmiko==3.3.2
ntc-templates==1.6.0
numpy==1.19.4
oauth2client==3.0.0
oauthlib==3.1.0
orionsdk==0.3.0
packaging==20.9
pandas==1.1.4
paramiko==2.7.1
pbr==5.5.1
pem==21.1.0
pexpect==4.8.0
ply==3.11
protobuf==3.13.0
ptyprocess==0.6.0
py2app==0.23
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
pycryptodome==3.4.11
pycryptodomex==3.9.9
pyeapi==0.8.4
pyinstaller==4.2
pyinstaller-hooks-contrib==2021.1
PyJWT==2.0.1
PyNaCl==1.4.0
pyOpenSSL==19.1.0
pyparsing==2.4.7
pyRFC3339==1.1
pyrsistent==0.17.3
pyserial==3.4
pysmi==0.3.4
pysnmp==4.4.12
python-dateutil==2.8.1
python-http-client==3.3.2
python-jose==3.0.1
pytz==2020.4
pyvmomi==7.0.1
PyYAML==5.4.1
requests==2.25.1
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
rsa==4.6
s3transfer==0.3.4
sc-chimera==1.0.500413
scp==0.13.3
sendgrid==6.6.0
six==1.15.0
spookey==1.0.1347
sqlparse==0.4.1
starkbank-ecdsa==1.1.0
tabulate==0.8.7
tenacity==6.2.0
textfsm==1.1.0
treelib==1.5.5
tzlocal==2.1
uritemplate==3.0.1
urllib3==1.25.11
virtualenv==20.4.3
Thanks for the feedback.
Here are vars I have in my playbook for cvaas
ansible_host: 'www.arista.io'
ansible_user: cvaas
ansible_ssh_pass: xxxxx
ansible_connection: httpapi
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_network_os: eos
ansible_httpapi_port: 443
Could you run the following before your playbook and in same shell as your playbook
$ export ANSIBLE_CVP_LOG_FILE=arista.cvp.debug.log
$ export ANSIBLE_CVP_LOG_APICALL=debug
$ export ANSIBLE_CVP_LOG_LEVEL=debug
# Run your playbook
$ ansible-playbook ...
# Share log in arista.cvp.debug.log in issue
Could you also confirm if pip is using same python interpreter as your ansible-playbook ?
HI @titom73
Please find the output below.
sshaurya@C02Z91Z8LVCH cvp_test -> export ANSIBLE_CVP_LOG_FILE=arista.cvp.debug.log
sshaurya@C02Z91Z8LVCH cvp_test -> export ANSIBLE_CVP_LOG_APICALL=debug
sshaurya@C02Z91Z8LVCH cvp_test -> export ANSIBLE_CVP_LOG_LEVEL=debug
sshaurya@C02Z91Z8LVCH cvp_test -> ansible-playbook -i hosts main.yaml -vvv
ansible-playbook 2.10.7
config file = /Users/sshaurya/Downloads/cvp_test/ansible.cfg
configured module search path = ['/Users/sshaurya/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.9.1 (default, Dec 17 2020, 03:41:37) [Clang 12.0.0 (clang-1200.0.32.27)]
Using /Users/sshaurya/Downloads/cvp_test/ansible.cfg as config file
host_list declined parsing /Users/sshaurya/Downloads/cvp_test/hosts as it did not pass its verify_file() method
auto declined parsing /Users/sshaurya/Downloads/cvp_test/hosts as it did not pass its verify_file() method
Parsed /Users/sshaurya/Downloads/cvp_test/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: main.yaml ***************************************************************
1 plays in main.yaml
PLAY [Playbook to demonstrate cv_container module.] *******************************
META: ran handlers
TASK [Gather CVP facts] ***********************************************************
task path: /Users/sshaurya/Downloads/cvp_test/main.yaml:9
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
redirecting (type: httpapi) ansible.builtin.eos to arista.eos.eos
redirecting (type: become) ansible.builtin.enable to ansible.netcommon.enable
<www.arista.io> ESTABLISH LOCAL CONNECTION FOR USER: sshaurya
<www.arista.io> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh `"&& mkdir "` echo /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/ansible-tmp-1618861983.245413-78987-222155471775391 `" && echo ansible-tmp-1618861983.245413-78987-222155471775391="` echo /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/ansible-tmp-1618861983.245413-78987-222155471775391 `" ) && sleep 0'
Using module file /Users/sshaurya/Documents/ansible-cvp/ansible_collections/arista/cvp/plugins/modules/cv_facts.py
<www.arista.io> PUT /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/tmpj_g8su2a TO /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/ansible-tmp-1618861983.245413-78987-222155471775391/AnsiballZ_cv_facts.py
<www.arista.io> EXEC /bin/sh -c 'chmod u+x /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/ansible-tmp-1618861983.245413-78987-222155471775391/ /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/ansible-tmp-1618861983.245413-78987-222155471775391/AnsiballZ_cv_facts.py && sleep 0'
<www.arista.io> EXEC /bin/sh -c '/usr/local/bin/python3 /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/ansible-tmp-1618861983.245413-78987-222155471775391/AnsiballZ_cv_facts.py && sleep 0'
<www.arista.io> EXEC /bin/sh -c 'rm -f -r /Users/sshaurya/.ansible/tmp/ansible-local-789832z6a7uzh/ansible-tmp-1618861983.245413-78987-222155471775391/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
File "/var/folders/36/dnqwqbw97pzg6xbrx45pr2vm0000gp/T/ansible_cv_facts_payload_xxcy5zav/ansible_cv_facts_payload.zip/ansible_collections/arista/cvp/plugins/module_utils/tools_cv.py", line 79, in cv_connect
client.connect(nodes=[host],
File "/usr/local/lib/python3.9/site-packages/cvprac/cvp_client.py", line 327, in connect
raise CvpLoginError(self.error_msg)
fatal: [www.arista.io]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"facts": [
"all"
],
"gather_subset": [
"default"
]
}
},
"msg": "\nwww.arista.io: Authenticate: https://www.arista.io:443/web/login/authenticate.do: Request Error: Not Found - <html>\r\n<head><title>404 Not Found</title></head>\r\n<body>\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/1.16.0</center>\r\n</body>\r\n</html>\r\n\n"
}
PLAY RECAP ************************************************************************
www.arista.io : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
sshaurya@C02Z91Z8LVCH cvp_test ->
sshaurya@C02Z91Z8LVCH cvp_test -> cat arista.cvp.debug.log
2021-04-19 12:53:04,224 - arista.cvp.cv_facts: INFO - func: <module> (L:110) - Start cv_facts module execution
2021-04-19 12:53:04,226 - arista.cvp.cv_tools: INFO - func: cv_connect (L:56 ) - Connecting to CVP
2021-04-19 12:53:04,230 - arista.cvp.cv_tools: DEBUG - func: cv_connect (L:74 ) - Connecting to a CV instance: www.arista.io with timers 30 30
2021-04-19 12:53:04,235 - urllib3.connectionpool: DEBUG - func: _new_conn (L:939) - Starting new HTTPS connection (1): www.arista.io:443
2021-04-19 12:53:05,363 - urllib3.connectionpool: DEBUG - func: _make_request (L:433) - https://www.arista.io:443 "POST /web/login/authenticate.do HTTP/1.1" 404 153
2021-04-19 12:53:05,364 - cvprac : ERROR - func: _is_good_response (L:402) - Authenticate: https://www.arista.io:443/web/login/authenticate.do: Request Error: Not Found - <html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.0</center>
</body>
</html>
2021-04-19 12:53:05,364 - cvprac : ERROR - func: _reset_session (L:364) - Authenticate: https://www.arista.io:443/web/login/authenticate.do: Request Error: Not Found - <html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.16.0</center>
</body>
</html>
sshaurya@C02Z91Z8LVCH cvp_test ->
Ok, so code is not switching to cvaas mode hence why you are still using API as on-premise server.
Please share version of collection installed
$ ansible-galaxy collection list | grep arista
Also, share result of the following command
$ ansible -m debug cvp -a "var=hostvars[inventory_hostname].ansible_user" -i </path/to/your/inventory/file>
sshaurya@C02Z91Z8LVCH cvp_test -> ansible -m debug cvp -a "var=hostvars[inventory_hostname].ansible_user" -i hosts
www.arista.io | SUCCESS => {
"hostvars[inventory_hostname].ansible_user": "cvaas # Shall not be changed. ansible will switch to cvaas mode"
}
sshaurya@C02Z91Z8LVCH cvp_test -> ansible-galaxy collection list | grep arista
arista.eos 1.3.0
arista.cvp 2.1.2
sshaurya@C02Z91Z8LVCH cvp_test ->
Ok, seems you have an error with your variable settings. it should not be
"cvaas # Shall not be changed. ansible will switch to cvaas mode"
But
"cvaas" # Shall not be changed. ansible will switch to cvaas mode
Please test and advise
Where an d how should I update this variable?
Below is a snippet of hosts file
sshaurya@C02Z91Z8LVCH cvp_test -> cat hosts
[cvp]
www.arista.io
[cvp:vars]
ansible_host=www.arista.io
ansible_python_interpreter=/usr/local/bin/python3
ansible_user=cvaas # Shall not be changed. ansible will switch to cvaas mode
Please do
---ansible_user=cvaas # Shall not be changed. ansible will switch to cvaas mode
+++ansible_user=cvaas
It works now, thanks @titom73
Happy it works fine. I will now move forward and close this issue.
Kind Regards
Hi Team, while trying out a basic ansible code (that worked before) with cvp we are now facing a "404 not found" error.
Exact error message from the ansible -vvv output is below:
"msg": "\nwww.arista.io: Authenticate: https://www.arista.io:443/web/login/authenticate.do: Request Error: Not Found - <html>\r\n<head><title>404 Not Found</title></head>\r\n<body>\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/1.16.0</center>\r\n</body>\r\n</html>\r\n\n"
Can someone please suggest what could be an issue here? Running a basic python script with cvp gives us an output so doesn't seem to be a connectivity, platform or module issue.