{"id":13715484,"url":"https://github.com/KeyboardInterrupt/ansible_xlsx_inventory","last_synced_at":"2025-05-07T04:30:48.193Z","repository":{"id":119810648,"uuid":"150971915","full_name":"KeyboardInterrupt/ansible_xlsx_inventory","owner":"KeyboardInterrupt","description":"Turn any Excel Sheet into an Ansible Inventory","archived":false,"fork":false,"pushed_at":"2020-09-22T04:33:33.000Z","size":38,"stargazers_count":97,"open_issues_count":5,"forks_count":34,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-14T03:34:29.640Z","etag":null,"topics":["ansible","dynamic-inventory","hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KeyboardInterrupt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-09-30T13:57:31.000Z","updated_at":"2024-05-15T14:58:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"6dc7f616-844c-4837-99be-5f68e940ca07","html_url":"https://github.com/KeyboardInterrupt/ansible_xlsx_inventory","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeyboardInterrupt%2Fansible_xlsx_inventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeyboardInterrupt%2Fansible_xlsx_inventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeyboardInterrupt%2Fansible_xlsx_inventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeyboardInterrupt%2Fansible_xlsx_inventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KeyboardInterrupt","download_url":"https://codeload.github.com/KeyboardInterrupt/ansible_xlsx_inventory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252813656,"owners_count":21808363,"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","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","dynamic-inventory","hacktoberfest"],"created_at":"2024-08-03T00:00:59.561Z","updated_at":"2025-05-07T04:30:47.840Z","avatar_url":"https://github.com/KeyboardInterrupt.png","language":"Python","funding_links":[],"categories":["Tools"],"sub_categories":[],"readme":"# Excel/Ansible Dynamic Inventory script\n\n## ToC\n\n- [Intro](#intro)\n- [Compatibility](#compatibility)\n- [Configuration](#configuration)\n- [Example File](#example-file)\n- [Grouping](#grouping)\n- [Hosts variables](#host-variables)\n- [Usage](#usage)\n- [Licens](#license)\n\n## Intro\n\nThis is a dynamic Inventory script for Ansible that turns an Excel Spreadsheet into an Inventory.\n\nThis is helpful whenever you get an Excel export from another Tool, containing Information on server, which you need to quickly access via Ansible, without manually writing an Inventory file beforehand.\n\n## Requirements\n\nThe following requirements must be installed to use this Inventory Script:\n\n- [Python](https://www.python.org/) - Python programming language\n- [OpenPyXL](https://openpyxl.readthedocs.io/en/stable/) - A Python library to read/write Excel 2010 xlsx/xlsm files\n\n## Compatibility\n\nSupported Excel file formats are:\n\n- `.xlsx`\n- `.xlsm`\n- `.xltx`\n- `.xltm`\n\nTested Ansible Version is: `2.6.2` (but it should be compatible with all Ansible version supporting Dynamic Inventory scripts)\n\n## Configuration\n\nTo make use of `xlsx_inventory.py` you must first specify some configuration inside the `xlsx_inventory.cfg` File.\n\nA Typical configuration file looks like this and is rather self explanatory:\n\n```ini\n[xlsx_inventory]\nxlsx_inventory_file = ./example.xlsx\nsheet = Sheet1\nhostname_col = A\ngroup_by_col = B\n```\n\nIf no such configuration file exists, you can easily create it by running:\n\n```bash\n./xlsx_inventory.py --config --file example.xlsx --hostname-col A --group-by-col B --sheet Sheet1\n```\n\n## Example File\n\nIncluded in this Repository is a Example Excel Spreadsheet, containing multiple sheets used to illustrate, and demonstrate in which ways xlsx_inventory.py can be used.\n\n- The first Sheet (__Sheet1__) contains a Export generated by a third party tool, which can easily be used as an Inventory\n- The second Sheet (__Sheet2__) contains an a Subset of (__Sheet1__) with additional Columns used to set/overwrite Ansible and custom variables.\n\n## Grouping and Hostnames\n\nServers can be grouped by any Column, i.E. with the included example file you could choose to group your hosts by the Column `B` (__Project__) or `D` (__Environment__) :\n\nThe example file also contains two possible Columns that could be used for unique Hostnames, either `A` (__VM Name__) or `E` (__DNS Name__) would be a good choices, depending on your DNS Settings/Environment.\n\n\n## Host variables\n\nAll Columns are automatically turned into Host Variables!\n\ni.E. the Host Variables for the Host `stg-zornfix-sql01` (row 35 in `Sheet1`) are:\n\n```json\n{\n    \"datacenter\": \"FRA-2\",\n    \"dns_name\": \"sql01.stg.zornfix.uk\",\n    \"environment\": \"Staging\",\n    \"project\": \"zornfix\",\n    \"vm_name\": \"stg-zornfix-sql01\"\n}\n```\n\nYou can use this to either set/overwrite ansible variables like `ansible_host` and `ansible_ssh_user` or to set/overwrite custom variables like `mysql_root_pass` (__example.xlsx Sheet2__)\n\n```json\n{\n    \"ansible_host\": \"10.13.37.01\",\n    \"ansible_ssh_user\": \"mysql-admin\",\n    \"datacenter\": \"FRA-1\",\n    \"dns_name\": \"sql01.dev.zornfix.uk\",\n    \"environment\": \"Development\",\n    \"mysql_root_pass\": \"Implosionsstrudel123!\",\n    \"project\": \"zornfix\",\n    \"vm_name\": \"dev-zornfix-sql01\"\n}\n\n```\n\nTo check which host variables are set by the inventory/xlsx file, you can run `xlsx_inventory.py --host \u003cHOSTNAME\u003e`\n\n## Usage\n\nOnce [configured](#configuration) the Inventory script can be used like any other Dynamic Inventory by specifying it as the inventory in your ansible/ansible-playbook commands:\n\n```bash\n./xlsx_inventory.py --config --file example.xlsx --group-by-col B --hostname-col A --sheet Sheet2\nansible -i xlsx_inventory.py -m ping dev-zornfix-app01\n```\n\n### Usage inside AWX or Ansible Tower\n\nIf you put your xlsx file inside of the same git repository as this script, then you can import the inventory contents via an SCM-based inventory source into an AWX or Ansible Tower server.\n\nStep by step instructions, must be done by a superuser:\n\n - Inside the Ansible virtualenv, install needed packages\n   - `pip install openpyxl`\n   - `pip install configparser`\n - Create a credential type that defines the inputs and injectors below (must be superuser)\n - Create a credential, providing any values unique to your project\n - Create an inventory\n - Create an inventory source\n   - source from project\n   - apply the credential from earlier\n   - select the inventory file `xlsx_inventory.py`\n - Save and update the inventory source\n\nThe inputs needed for the credential type:\n\n```yaml\nfields:\n  - type: string\n    id: excel_file\n    label: Location of Excel file\n  - type: string\n    id: group_by_col\n    label: Column letter to group hosts by\n  - type: string\n    id: hostname_col\n    label: Column that contains hostnames\n  - type: string\n    id: sheet\n    label: Sheet in Excel to use\n```\n\nInjectors needed for the credential type:\n\n```yaml\nenv:\n  EXCEL_INVENTORY_CONFIG: '{{tower.filename}}'\nfile:\n  template: |-\n    [xlsx_inventory]\n    xlsx_inventory_file = {{excel_file | default('example.xlsx')}}\n    group_by_col = {{group_by_col | default('B')}}\n    hostname_col = {{ hostname_col | default('A') }}\n    sheet = {{ sheet | default('Sheet1') }}\n```\n\n## License\n\nThis project is licensed under the GPL3 License - see the [LICENSE.md](/LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKeyboardInterrupt%2Fansible_xlsx_inventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKeyboardInterrupt%2Fansible_xlsx_inventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKeyboardInterrupt%2Fansible_xlsx_inventory/lists"}