{"id":16779648,"url":"https://github.com/ahuffman/api","last_synced_at":"2025-10-14T20:13:15.833Z","repository":{"id":69819600,"uuid":"143216022","full_name":"ahuffman/api","owner":"ahuffman","description":"An Ansible role to avoid having to fill in repetitive parameters when writing a playbook with multiple API calls.","archived":false,"fork":false,"pushed_at":"2021-07-19T21:39:18.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-14T20:13:11.929Z","etag":null,"topics":["ansible","ansible-role","api"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahuffman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-01T22:49:31.000Z","updated_at":"2021-07-19T21:39:20.000Z","dependencies_parsed_at":"2023-02-24T14:00:42.031Z","dependency_job_id":null,"html_url":"https://github.com/ahuffman/api","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ahuffman/api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahuffman%2Fapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahuffman%2Fapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahuffman%2Fapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahuffman%2Fapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahuffman","download_url":"https://codeload.github.com/ahuffman/api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahuffman%2Fapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279021006,"owners_count":26086946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-role","api"],"created_at":"2024-10-13T07:31:19.389Z","updated_at":"2025-10-14T20:13:15.827Z","avatar_url":"https://github.com/ahuffman.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"![Ansible Role](https://img.shields.io/ansible/role/d/28010)\n\n# ahuffman.api\nAn Ansible role to avoid having to fill in repetitive parameters when writing a playbook with multiple API calls.  This role wraps around the Ansible [`uri`](https://docs.ansible.com/ansible/latest/modules/uri_module.html#uri-module) module.  This helps reduce tedious playbook writing and makes the overall playbook more readable while reducing repetitive lines of code.\n\n## Role Variables\nWhere the default value \"omit\" is noted, refer to the Ansible [`uri`](https://docs.ansible.com/ansible/latest/modules/uri_module.html#uri-module) module documentation for the inherited defaults.\n\n|Variable Name|Required|Description|Type|Default|\n|---|:---:|---|:---:|:---:|\n|api_task_name|no|Name of the task to run the uri/api task with.|string|\"API Task\"|\n|api_body|yes|Body of the request.|string|omit|\n|api_body_format|no|The serialization format of the body.|string|\"json\"|\n|api_client_cert|no|PEM formatted certificate chain file to be used for SSL client authentication.|string|omit|\n|api_client_key|no|PEM formatted file that contains your private key to be used for SSL client authentication.|string|omit|\n|api_creates|no|A filename, when it already exists, this step will not be run.|string|omit|\n|api_dest|no|A path of where to download the file to (if desired).|string|omit|\n|api_follow_redirects|no|Whether or not the URI module should follow redirects.|string|omit|\n|api_force_basic_auth|no|The library used by the uri module only sends authentication information when a webservice responds to an initial request with a 401 status.|boolean|True|\n|api_headers|no|Add custom HTTP headers to a request in the format of a YAML hash.|list|omit|\n|api_method|no|The HTTP method of the request or response. It MUST be uppercase.|string|\"GET\"|\n|api_others|no|All arguments accepted by the file module also work here|list|omit|\n|api_pass|no|Password for your API request user|string|\"\"|\n|api_removes|no|A filename, when it does not exist, this step will not be run.|string|omit|\n|api_return_content|no|Whether or not to return the body of the response as a \"content\" key in the dictionary result.|boolean|omit|\n|api_status_code|no|Comma separated list of valid, numeric, HTTP status codes that signifies success of the request.|string|\"200\"|\n|api_timeout|no|The socket level timeout in seconds|string|omit|\n|api_base_url|yes|The base URL that you would like to perform requests against|string|\"\"|\n|api_url_path|no|The extended path of the URL that you would like to perform requests against|string|\"\"|\n|api_user|no|User for your API request|string|omit|\n|api_validate_certs|no|Whether or not to validate SSL certificates|boolean|omit|\n\n## Returned Variables\nThis role returns the results of API requests with a variable called `api_results`.  Prior to Ansible 2.8 the `register` keyword was templatable and we utilized a variable called `api_register_var`.  Unfortunately this is no longer functional in Ansible 2.8.  \n\nTo retrieve the results of an API request, simply reference `api_results` after instantiating this role.\n\n## Example Playbook\n```yaml\n    ---\n    - hosts: \"all\"\n      vars:\n        api_base_url: \"https://myserver.mydomain.com\"\n        api_user: \"someuser\"\n        api_pass: \"strongp@$$\" #you should store this in a ansible-vault\n      tasks:\n        - include_role:\n            name: \"api\"\n          vars:\n            api_task_name: \"Get some data from webservice\"\n            api_url_path: \"api/hosts\"\n            api_body: \"{\\\"search\\\": \\\"myhostname.mydomain.com\\\"}\"  #for large bodies, use a template lookup here\n\n        - name: \"Output results\"\n          debug:\n            var: \"api_results\"\n```\n## License\n[MIT](LICENSE)\n\n## Author Information\n[Andrew J. Huffman](https://github.com/ahuffman)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahuffman%2Fapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahuffman%2Fapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahuffman%2Fapi/lists"}