{"id":24911268,"url":"https://github.com/mriceman11/checkmk_ansible_inventory","last_synced_at":"2025-08-28T02:49:11.358Z","repository":{"id":273347866,"uuid":"919401947","full_name":"MrIceman11/Checkmk_Ansible_Inventory","owner":"MrIceman11","description":"Checkmk to Ansible Inventory Script","archived":false,"fork":false,"pushed_at":"2025-01-20T10:33:28.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T02:51:51.720Z","etag":null,"topics":["ansible","checkmk"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrIceman11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-01-20T10:24:26.000Z","updated_at":"2025-01-20T10:34:08.000Z","dependencies_parsed_at":"2025-01-20T11:32:31.072Z","dependency_job_id":"147b5980-07ce-4e49-9970-890c7757218d","html_url":"https://github.com/MrIceman11/Checkmk_Ansible_Inventory","commit_stats":null,"previous_names":["mriceman11/checkmk_ansible_inventory"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MrIceman11/Checkmk_Ansible_Inventory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrIceman11%2FCheckmk_Ansible_Inventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrIceman11%2FCheckmk_Ansible_Inventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrIceman11%2FCheckmk_Ansible_Inventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrIceman11%2FCheckmk_Ansible_Inventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrIceman11","download_url":"https://codeload.github.com/MrIceman11/Checkmk_Ansible_Inventory/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrIceman11%2FCheckmk_Ansible_Inventory/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272424911,"owners_count":24932895,"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-08-28T02:00:10.768Z","response_time":74,"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","checkmk"],"created_at":"2025-02-02T04:19:02.134Z","updated_at":"2025-08-28T02:49:11.319Z","avatar_url":"https://github.com/MrIceman11.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\nThis Python script retrieves host information from a Checkmk instance, filters them based on specified folders, and generates an Ansible-compatible inventory file in YAML format. The inventory groups are dynamically created based on the folders specified in the configuration.\n\n## Prerequisites\n1. **Python 3.x**: Ensure you have Python 3 installed.\n2. **Required Libraries**:\n   - `requests`\n   - `pyyaml`\n   \n   Install them using:\n   ```bash\n   pip install requests pyyaml\n   ```\n3. **Checkmk API Access**:\n   - A valid Checkmk server URL.\n   - API username and password with sufficient permissions.\n\n## Configuration\n### Modify the following options in the script:\n\n- **Checkmk Server Details**:\n  ```python\n  HOST_NAME = \"your.cmk.server\"\n  SITE_NAME = \"mysite\"\n  PROTO = \"https\"  # [http|https]\n  ```\n  \n- **Authentication**:\n  ```python\n  USERNAME = \"your_username\"\n  PASSWORD = \"your_password\"\n  ```\n\n- **Folders to Filter**:\n  Specify the Checkmk folders and their corresponding Ansible group names:\n  ```python\n  FOLDERS = {\n      \"/it/linux\": \"linux\",\n      \"/os/winserver\": \"windows\",\n  }\n  ```\n\n- **Output File Name**:\n  Define the name of the YAML file:\n  ```python\n  OUTPUT_FILE = \"custom_hosts.yaml\"\n  ```\n\n## How It Works\n1. **API Call**: The script fetches all hosts from the Checkmk instance.\n2. **Filtering**: Hosts are filtered based on their folder (e.g., `/it/linux`, `/it/winserver`).\n3. **YAML File Generation**: The filtered hosts are grouped by folder and written to an Ansible-compatible YAML inventory file.\n\n## Usage\n1. Save the script to a file, e.g., `checkmk_to_ansible.py`.\n2. Run the script:\n   ```bash\n   python3 checkmk_to_ansible.py\n   ```\n3. The script generates a YAML file (e.g., `custom_hosts.yaml`) in the current directory.\n\n## Example Output\nHere is an example of the generated YAML file:\n\n```yaml\nall:\n  children:\n    Linux:\n      hosts:\n        linux-host-1:\n          ansible_host: 192.168.1.10\n        linux-host-2:\n          ansible_host: 192.168.1.11\n    Windows:\n      hosts:\n        windows-host-1:\n          ansible_host: 192.168.2.10\n        windows-host-2:\n          ansible_host: 192.168.2.11\n```\n\n## Error Handling\n- If the API call fails, the script raises an exception with the API response.\n- If a host does not contain the expected attributes (e.g., IP address), the script logs an error message but continues processing other hosts.\n\n## Extending the Script\n- **Adding More Groups**: Add additional folders and group names to the `FOLDERS` dictionary.\n- **Custom Output**: Modify the `write_to_ansible_yaml` function to adjust the YAML structure.\n\n## Troubleshooting\n1. **401 Unauthorized**: Check your username and password.\n2. **404 Not Found**: Ensure the API URL is correct and accessible.\n3. **Dependencies Missing**: Install required libraries using `pip install requests pyyaml`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmriceman11%2Fcheckmk_ansible_inventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmriceman11%2Fcheckmk_ansible_inventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmriceman11%2Fcheckmk_ansible_inventory/lists"}