Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awx.awx.tower_host trouble use from NOT awx server (where pyyaml not installed) #6983

Closed
dolgovas opened this issue May 11, 2020 · 8 comments
Assignees
Labels
component:awx_collection issues related to the collection for controlling AWX type:bug

Comments

@dolgovas
Copy link

ISSUE TYPE
  • Bug Report
SUMMARY

awx.awx collection does not work correctly

ENVIRONMENT
  • AWX version: 11.2.0
  • AWX install method: docker on linux
  • Ansible version: 2.9.7
  • Operating System: macos
  • Web Browser: Firefox
STEPS TO REPRODUCE

add hosts via playbook through awx.awx.tower_host
tower_cli config

cat ~/tower_cli.cfg
[general]
host = https://awx.local.lan
verify_ssl = false
oauth_token = OBaCofjahsdlfkjhalsdjfELUHomaCxRWfnNM

inventory

ansible -m debug -a 'var=ansible_host' awx
awx-docker1 | SUCCESS => {
    "ansible_host": "192.168.10.10"
}

playbook adding hosts

---
- name: Playbook for Using a Variety of Tower Modules
  hosts: awx
  gather_facts: false
  become: false
  collections:
    - awx.awx

  tasks:
  - name: Create a Host
    tower_host:
      name: "New Host"
      inventory: "New inventory"
      state: present
      variables:
         ansible_host: 10.10.10.10
EXPECTED RESULTS

add host into awx

ACTUAL RESULTS
ansible-playbook awx_add_hosts.yml
PLAY [Playbook for Using a Variety of Tower Modules] ****************************************************************************************************************************************

TASK [Create a Host] ************************************************************************************************************************************************************************
Monday 11 May 2020  10:38:32 +0300 (0:00:00.235)       0:00:00.235 ************
[WARNING]: Failed to release tower token None: hostname '127.0.0.1' doesn't match either of 'local.lan', '*.local.lan'
fatal: [awx-docker1]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false
}

MSG:

There was an unknown error when trying to connect to https://127.0.0.1/api/v2/inventories/?name=New+inventory: CertificateError hostname '127.0.0.1' doesn't match either of 'local.lan', '*.local.lan'
	to retry, use: --limit @.ansible-retry/awx_add_hosts.retry

PLAY RECAP **********************************************************************************************************************************************************************************
awx-docker1                : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Monday 11 May 2020  10:38:34 +0300 (0:00:01.298)       0:00:01.534 ************
===============================================================================
Create a Host ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 1.30s
ADDITIONAL INFORMATION
@AlanCoding AlanCoding added the component:awx_collection issues related to the collection for controlling AWX label May 11, 2020
@AlanCoding
Copy link
Member

hosts: awx

When you ran the command cat ~/tower_cli.cfg, where did you run that? From your own machine, or from the "awx" server?

From the looks of what you're doing, maybe the task should be delegate_to: localhost. That makes sense if your networking allows your computer access to the server via the normal ports for the API and UI to work.

The config is read from wherever the task is ran. It looks like, since the task ran on the server, there was no config file and it fell back to default values.

Environment vars (set in ansible-playbook context) & config file don't work to specify auth parameters if not ran from localhost. I'm all for improving the docs on this, but it needs to be said that it's a problem shared with other cloud modules, and is very often confusing. I'd like to see some examples of it done right.

@dolgovas
Copy link
Author

When you ran the command cat ~/tower_cli.cfg, where did you run that? From your own machine, or from the "awx" server?

from my own machine, which has tcp access to awx server

some later i'll try play this things again with local_action

@dolgovas
Copy link
Author

some later i'll try play this things again with local_action

file on my machine

cat ~/tower_cli.cfg
[general]
host = https://awx.local.lan
verify_ssl = false
oauth_token = OBaCofMWWfnNM

playbook

---
- name: Playbook for Using a Variety of Tower Modules
  hosts: localhost
  gather_facts: false
  become: false
  collections:
    - awx.awx

  tasks:
  - name: Create a Host
    tower_host:
      name: "New Host"
      inventory: "New inventory"
      state: present
      variables:
         ansible_host: 10.10.10.10

result

PLAY [Playbook for Using a Variety of Tower Modules] ****************************************************************************************************************************************

TASK [Create a Host] ************************************************************************************************************************************************************************
Monday 11 May 2020  16:20:45 +0300 (0:00:00.232)       0:00:00.232 ************
[WARNING]: Failed to release tower token None: <urlopen error [Errno 61] Connection refused>
[WARNING]: Platform darwin on host localhost is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
fatal: [localhost]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false
}

MSG:

There was an unknown error when trying to connect to https://127.0.0.1/api/v2/inventories/?name=New+inventory: URLError <urlopen error [Errno 61] Connection refused>
	to retry, use: --limit @.ansible-retry/test.awx.retry

PLAY RECAP **********************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Monday 11 May 2020  16:20:46 +0300 (0:00:00.402)       0:00:00.634 ************
===============================================================================
Create a Host ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.40s

@AlanCoding
Copy link
Member

Could you try ~/.tower_cli.cfg instead of ~/tower_cli.cfg? The former is what we have in the README.md.

@dolgovas
Copy link
Author

Could you try ~/.tower_cli.cfg instead of ~/tower_cli.cfg? The former is what we have in the README.md.

cat ~/.tower_cli.cfg
[general]
host = https://awx.local.lan
verify_ssl = false
oauth_token = OBaCofMWWfnNM

something interesting ))

PLAY [Playbook for Using a Variety of Tower Modules] ****************************************************************************************************************************************

TASK [Create a Host] ************************************************************************************************************************************************************************
Monday 11 May 2020  17:54:29 +0300 (0:00:00.241)       0:00:00.241 ************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: NameError: global name 'yaml' is not defined
[WARNING]: Platform darwin on host localhost is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
fatal: [localhost]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "rc": 1
}

MSG:

MODULE FAILURE
See stdout/stderr for the exact error


MODULE_STDERR:

Traceback (most recent call last):
  File "<stdin>", line 102, in <module>
  File "<stdin>", line 94, in _ansiballz_main
  File "<stdin>", line 40, in invoke_module
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 188, in run_module
    fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/var/folders/fs/11pwzff15dsdz5ky0sc8pyq80000gn/T/ansible_tower_host_payload_PgW2Gy/ansible_tower_host_payload.zip/ansible_collections/awx/awx/plugins/modules/tower_host.py", line 142, in <module>
  File "/var/folders/fs/11pwzff15dsdz5ky0sc8pyq80000gn/T/ansible_tower_host_payload_PgW2Gy/ansible_tower_host_payload.zip/ansible_collections/awx/awx/plugins/modules/tower_host.py", line 100, in main
  File "/var/folders/fs/11pwzff15dsdz5ky0sc8pyq80000gn/T/ansible_tower_host_payload_PgW2Gy/ansible_tower_host_payload.zip/ansible_collections/awx/awx/plugins/module_utils/tower_api.py", line 65, in __init__
  File "/var/folders/fs/11pwzff15dsdz5ky0sc8pyq80000gn/T/ansible_tower_host_payload_PgW2Gy/ansible_tower_host_payload.zip/ansible_collections/awx/awx/plugins/module_utils/tower_api.py", line 111, in load_config_files
  File "/var/folders/fs/11pwzff15dsdz5ky0sc8pyq80000gn/T/ansible_tower_host_payload_PgW2Gy/ansible_tower_host_payload.zip/ansible_collections/awx/awx/plugins/module_utils/tower_api.py", line 152, in load_config
NameError: global name 'yaml' is not defined

	to retry, use: --limit @/Users/meonacist/.ansible-retry/test.awx.retry

PLAY RECAP **********************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Monday 11 May 2020  17:54:29 +0300 (0:00:00.364)       0:00:00.605 ************
===============================================================================
Create a Host ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 0.36s

@AlanCoding
Copy link
Member

except(AttributeError, yaml.YAMLError, AssertionError):

Yeah, looks like the error handling catches things in the wrong order

@AlanCoding AlanCoding changed the title awx.awx.tower_host trouble use from NOT awx server awx.awx.tower_host trouble use from NOT awx server (where pyyaml not installed) May 13, 2020
@kdelee
Copy link
Member

kdelee commented Jul 7, 2020

@dolgovas I tried out your example playbook + config and this is working for me, so I'm going to close the issue. If you are still having trouble please let us know and re-open the issue w/ updated information

@kdelee kdelee closed this as completed Jul 7, 2020
@kdelee kdelee self-assigned this Jul 7, 2020
@dolgovas
Copy link
Author

#6983 (comment)
I checked it the day before this playbook - everything works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:awx_collection issues related to the collection for controlling AWX type:bug
Projects
None yet
Development

No branches or pull requests

4 participants