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

Add output to determine inventory upload failure #34

Open
jon-nfc opened this issue Oct 31, 2024 · 1 comment
Open

Add output to determine inventory upload failure #34

jon-nfc opened this issue Oct 31, 2024 · 1 comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed type::feature type for Issues and Merge Requests. Can also be used in discussion in comments and commits
Milestone

Comments

@jon-nfc
Copy link
Member

jon-nfc commented Oct 31, 2024

failure to upload an inventory should show output.

Details

  • - name: Upload inventory - {{ ansible_hostname }}
    ansible.builtin.uri:
    url: |-
    {{ lookup('env', 'ITSM_API') }}/api/device/inventory
    method: POST
    body_format: json
    src: "/tmp/{{ ansible_hostname }}.json"
    remote_src: true
    headers:
    Authorization: Token {{ lookup('env', 'ITSM_TOKEN') }}
    validate_certs: "{{ lookup('env', 'ITSM_VALIDATE_CERTS') | default(true) | bool }}"
    timeout: 300
    status_code:
    - 200
    - 201
    no_log: > # Contains a secret that logging shows
    {{ nfc_pb_disable_log | default(true) }}

The inventory upload task should be inside a block so that a task can be setup to show the HTTP status code and the message .msg to stdout on error.

Example ERROR json

{
  "redirected": false,
  "url": "--- truncated---",
  "status": 401,
  "date": "Thu, 31 Oct 2024 15:18:09 GMT",
  "content_type": "application/json",
  "content_length": "58",
  "connection": "close",
  "www_authenticate": "Token",
  "vary": "Accept, Cookie",
  "allow": "POST, OPTIONS",
  "x_frame_options": "DENY",
  "x_content_type_options": "nosniff",
  "referrer_policy": "same-origin",
  "cross_origin_opener_policy": "same-origin",
  "strict_transport_security": "max-age=15724800; includeSubDomains",
  "elapsed": 3,
  "changed": false,
  "json": {
    "detail": "Authentication credentials were not provided."
  },
  "msg": "Status code was 401 and not [200, 201]: HTTP Error 401: Unauthorized",
  "invocation": {
    "module_args": {
      "url": "--- truncated---",
      "method": "POST",
      "body_format": "json",
      "src": "/tmp/--- truncated---.json",
      "remote_src": true,
      "headers": {
        "Authorization": "Token --- truncated---",
        "Content-Type": "application/json",
        "Content-Length": 32922
      },
      "validate_certs": false,
      "timeout": 300,
      "status_code": [
        200,
        201
      ],
      "force": false,
      "http_agent": "ansible-httpget",
      "use_proxy": true,
      "force_basic_auth": false,
      "use_gssapi": false,
      "return_content": false,
      "follow_redirects": "safe",
      "unredirected_headers": [],
      "decompress": true,
      "use_netrc": true,
      "unsafe_writes": false,
      "url_username": null,
      "url_password": null,
      "client_cert": null,
      "client_key": null,
      "dest": null,
      "body": null,
      "creates": null,
      "removes": null,
      "unix_socket": null,
      "ca_path": null,
      "ciphers": null,
      "mode": null,
      "owner": null,
      "group": null,
      "seuser": null,
      "serole": null,
      "selevel": null,
      "setype": null,
      "attributes": null
    }
  },
  "_ansible_no_log": false
}
@jon-nfc jon-nfc added help wanted Extra attention is needed good first issue Good for newcomers type::feature type for Issues and Merge Requests. Can also be used in discussion in comments and commits labels Oct 31, 2024
@jon-nfc jon-nfc added this to the next release milestone Oct 31, 2024
@jon-nfc jon-nfc moved this to Backlog in Centurion ERP Oct 31, 2024
@pvcasillasg
Copy link

PR: #35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed type::feature type for Issues and Merge Requests. Can also be used in discussion in comments and commits
Projects
Status: In progress
Development

No branches or pull requests

2 participants