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

Failed to get token: HTTP Error 404 #15727

Open
5 of 11 tasks
markfaine opened this issue Dec 28, 2024 · 2 comments
Open
5 of 11 tasks

Failed to get token: HTTP Error 404 #15727

markfaine opened this issue Dec 28, 2024 · 2 comments

Comments

@markfaine
Copy link

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that AWX is open source software provided for free and that I might not receive a timely response.
  • I am NOT reporting a (potential) security vulnerability. (These should be emailed to [email protected] instead.)

Bug Summary

In a docker container as part of a CI/CD job I have installed ansible.controller collection to use the inventory plugin.

I have configured the necessary arguments as environment variables:

export CONTROLLER_HOST=MY_HOST
export CONTROLLER_USERNAME=MY_USER
export CONTROLLER_PASSWORD="MY PASSWORD"
export CONTROLLER_INVENTORY=MY_INVENTORY_ID

Error Message:

[WARNING]:  * Failed to parse /home/ansible/@controller_inventory with ansible_collections.ansible.controller.plugins.inventory.controller plugin: Failed to get token: HTTP Error 404: Not
Found
  File "/home/ansible/venv/lib/python3.12/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/inventory/controller.py", line 139, in parse
    inventory = module.get_endpoint(inventory_url, data={'hostvars': '1', 'towervars': '1', 'all': '1'})['json']
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 346, in get_endpoint
    return self.make_request('GET', endpoint, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 493, in make_request
    self.authenticate(**kwargs)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 658, in authenticate
    self.fail_json(msg='Failed to get token: {0}'.format(he), response=resp)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 276, in fail_json
    self.error_callback(**kwargs)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/inventory/controller.py", line 79, in handle_error
    raise AnsibleParserError(to_native(kwargs.get('msg')))

I am able to hit the AAP server with curl just fine with:

 curl -u "myuser:mypass"  "https://myhost/api/v2/inventories/my_inventory_id/script/"

So I have eliminated any issues with firewall, proxy, ssl.

AWX version

AAP Controller 4.5.6, ansible.controller collection 4.6.3

Select the relevant components

  • UI
  • UI (tech preview)
  • API
  • Docs
  • Collection
  • CLI
  • Other

Installation method

docker development environment

Modifications

no

Ansible version

2.16.6

Operating system

debian trixie-slim container

Web browser

Firefox

Steps to reproduce

mkdir -p "$HOME/.ssh"
cat "${SSH_CONFIG_FILE}" > "$HOME/.ssh/config"
cat "${SSH_KEY_FILE}" > "$HOME/.ssh/id_rsa"
chmod -R u+rwX,g-rwX,o-rwX "$HOME/.ssh"
cat "${ANSIBLE_CFG_FILE}" > "$HOME/ansible.cfg"
export ANSIBLE_CONFIG="$HOME/ansible.cfg" 
export CONTROLLER_HOST=MYHOST
export CONTROLLER_USERNAME=MYUSER
export CONTROLLER_PASSWORD="MY_PASSWORD"
export CONTROLLER_INVENTORY=MY_INVENTORY_ID
. "$HOME/venv/bin/activate"
echo "${VAULT_PASSWORD}" > "$HOME/.vault"
chmod 600 "$HOME/.vault"
export ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_URL="${AAP_CERTIFIED_CONTENT_URL}"
export ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_AUTH_URL="${REDHAT_SSO_URL}"
export ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN="${AAP_TOKEN}"  
ansible-galaxy collection install ansible.controller  
ansible-inventory -i @controller_inventory --list 

Expected results

The output of ansible-inventory --list according the the inventory id selected.

Actual results

[WARNING]:  * Failed to parse /home/ansible/@controller_inventory with ansible_collections.ansible.controller.plugins.inventory.controller plugin: Failed to get token: HTTP Error 404: Not
Found
  File "/home/ansible/venv/lib/python3.12/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/inventory/controller.py", line 139, in parse
    inventory = module.get_endpoint(inventory_url, data={'hostvars': '1', 'towervars': '1', 'all': '1'})['json']
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 346, in get_endpoint
    return self.make_request('GET', endpoint, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 493, in make_request
    self.authenticate(**kwargs)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 658, in authenticate
    self.fail_json(msg='Failed to get token: {0}'.format(he), response=resp)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/module_utils/controller_api.py", line 276, in fail_json
    self.error_callback(**kwargs)
  File "/home/ansible/.ansible/collections/ansible_collections/ansible/controller/plugins/inventory/controller.py", line 79, in handle_error
    raise AnsibleParserError(to_native(kwargs.get('msg')))
[WARNING]: Unable to parse /home/ansible/@controller_inventory as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
   452 1735408533.88192: '/home/ansible/venv/lib/python3.12/site-packages/ansible/plugins/vars/__init__' skipped due to reserved name
   452 1735408533.88304: trying /home/ansible/venv/lib/python3.12/site-packages/ansible/plugins/doc_fragments
   452 1735408533.88364: Loading ModuleDocFragment 'vars_plugin_staging' from /home/ansible/venv/lib/python3.12/site-packages/ansible/plugins/doc_fragments/vars_plugin_staging.py
   452 1735408533.88388: Loaded config def from plugin (vars/host_group_vars)
   452 1735408533.88392: Loading VarsModule 'host_group_vars' from /home/ansible/venv/lib/python3.12/site-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=False, class_only=True)
   452 1735408533.88402: trying /home/ansible/venv/lib/python3.12/site-packages/ansible/plugins/vars
   452 1735408533.88413: Loading VarsModule 'host_group_vars' from /home/ansible/venv/lib/python3.12/site-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
   452 1735408533.88446: Loading CacheModule 'memory' from /home/ansible/venv/lib/python3.12/site-packages/ansible/plugins/cache/memory.py (found_in_cache=True, class_only=False)
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

Additional information

No response

@markfaine
Copy link
Author

Checked another server and saw it was running ansible.controller 4.5.7 and it works fine with the same pipeline configuration. It seems to be specific to 4.6.3 and perhaps versions above 4.5.7.

@stratus-ss
Copy link

I have a similar with Docker install of AWX version: AWX 24.6.2.dev205+g14808cb99b.d20241227

When I look at the logs of the tools container I see

2025-01-01 18:24:52,706 WARNING  [06e2ae67] django.request Not Found: /api/v2/users/2/personal_tokens/
2025-01-01 18:24:52,706 WARNING  [06e2ae67] django.request Not Found: /api/v2/users/2/personal_tokens/

If I try to create a token for my user in the UI I see

2025-01-01 18:29:23,766 WARNING  [0f96a971] django.request Not Found: /api/v2/tokens/
2025-01-01 18:29:23,766 WARNING  [0f96a971] django.request Not Found: /api/v2/tokens/

When I examine the API, these endpoints are missing

    "activity_stream": "/api/v2/activity_stream/",
    "ad_hoc_commands": "/api/v2/ad_hoc_commands/",
    "analytics": "/api/v2/analytics/",
    "bulk": "/api/v2/bulk/",
    "config": "/api/v2/config/",
    "constructed_inventory": "/api/v2/constructed_inventories/",
    "credential_input_sources": "/api/v2/credential_input_sources/",
    "credentials": "/api/v2/credentials/",
    "credential_types": "/api/v2/credential_types/",
    "dashboard": "/api/v2/dashboard/",
    "execution_environments": "/api/v2/execution_environments/",
    "groups": "/api/v2/groups/",
    "host_metrics": "/api/v2/host_metrics/",
    "host_metric_summary_monthly": "/api/v2/host_metric_summary_monthly/",
    "hosts": "/api/v2/hosts/",
    "instance_groups": "/api/v2/instance_groups/",
    "instances": "/api/v2/instances/",
    "inventory": "/api/v2/inventories/",
    "inventory_sources": "/api/v2/inventory_sources/",
    "inventory_updates": "/api/v2/inventory_updates/",
    "jobs": "/api/v2/jobs/",
    "job_templates": "/api/v2/job_templates/",
    "labels": "/api/v2/labels/",
    "me": "/api/v2/me/",
    "mesh_visualizer": "/api/v2/mesh_visualizer/",
    "metrics": "/api/v2/metrics/",
    "notifications": "/api/v2/notifications/",
    "notification_templates": "/api/v2/notification_templates/",
    "organizations": "/api/v2/organizations/",
    "ping": "/api/v2/ping/",
    "projects": "/api/v2/projects/",
    "project_updates": "/api/v2/project_updates/",
    "receptor_addresses": "/api/v2/receptor_addresses/",
    "role_definitions": "/api/v2/role_definitions/",
    "roles": "/api/v2/roles/",
    "role_team_assignments": "/api/v2/role_team_assignments/"
    "role_user_assignments": "/api/v2/role_user_assignments/",
    "schedules": "/api/v2/schedules/",
    "service_index": "/api/v2/service-index/",
    "settings": "/api/v2/settings/",
    "system_jobs": "/api/v2/system_jobs/",
    "system_job_templates": "/api/v2/system_job_templates/",
    "teams": "/api/v2/teams/",
    "unified_jobs": "/api/v2/unified_jobs/",
    "unified_job_templates": "/api/v2/unified_job_templates/",
    "users": "/api/v2/users/",
    "workflow_approvals": "/api/v2/workflow_approvals/",
    "workflow_job_nodes": "/api/v2/workflow_job_nodes/",
    "workflow_jobs": "/api/v2/workflow_jobs/",
    "workflow_job_template_nodes": "/api/v2/workflow_job_template_nodes/",
    "workflow_job_templates": "/api/v2/workflow_job_templates/",

The documentation shows that these endpoints should exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants