{"id":20154745,"url":"https://github.com/techdad/ansible-role-hosts-file","last_synced_at":"2026-05-13T09:10:26.744Z","repository":{"id":84557064,"uuid":"130363613","full_name":"techdad/ansible-role-hosts-file","owner":"techdad","description":"A simple role to populate an `/etc/hosts` file.","archived":false,"fork":false,"pushed_at":"2018-05-02T12:50:22.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-03T01:32:03.863Z","etag":null,"topics":["ansible","hosts-file","hostsfile","os"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techdad.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}},"created_at":"2018-04-20T13:09:15.000Z","updated_at":"2018-05-02T12:52:31.000Z","dependencies_parsed_at":"2023-03-12T23:35:17.647Z","dependency_job_id":null,"html_url":"https://github.com/techdad/ansible-role-hosts-file","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/techdad/ansible-role-hosts-file","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techdad%2Fansible-role-hosts-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techdad%2Fansible-role-hosts-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techdad%2Fansible-role-hosts-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techdad%2Fansible-role-hosts-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techdad","download_url":"https://codeload.github.com/techdad/ansible-role-hosts-file/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techdad%2Fansible-role-hosts-file/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32975315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T06:31:55.726Z","status":"ssl_error","status_checked_at":"2026-05-13T06:31:51.336Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","hosts-file","hostsfile","os"],"created_at":"2024-11-13T23:28:16.187Z","updated_at":"2026-05-13T09:10:26.727Z","avatar_url":"https://github.com/techdad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ansible Role: hosts-file\n\nThis is a super simple role with a single task and template to populate an `/etc/hosts` file from the given list variable.\n\nThe use-case is generally for systems like database cluster members, where it's desired that they can intercommunicate by name, even in the event of outside network access (and thus DNS) failure.\n\nPlease *do NOT* consider this a way to forego configuring real DNS for an environment!\n\n## Role Variables:\n\n| Parameter     | Default     |\n|---------------|-------------|\n| `hosts_hosts` | `[]` (none) |\n\nPopulate this with a list of dictionary entries that will be the lines to add to the `/etc/hosts` file, excluding `localhost`.\n\nIf empty, or not set, then *only* the default `localhost` entries are added.\n\n### Format:\n\n```yaml\nhosts_hosts:\n  - name: \n    ipv4: \n    ipv6: \n```\n\n### Details:\n\n* Do *not* add in 'localhost' entries. You can, but the are redundant and always added at the top in any case.\n* Always use *short* **hostnames** - the systems default domain is also automatically appended as an additional name.\n* Always have both `ipv4:` and `ipv6:` listed, even if one or the other is empty.\n\n### Working Example:\n\n```yaml\n# hosts file variable\nhosts_hosts:\n  - name: \"dualstack\"\n    ipv4: \"192.0.2.46\"\n    ipv6: \"2001:db8:192:2::46\"\n  - name: \"ipv4only\"\n    ipv4: \"192.0.2.44\"\n    ipv6:\n  - name: \"ipv6only\"\n    ipv4:\n    ipv6: \"2001:db8:192:2::66\"\n```\n\n... would result in:\n\n```\n# Ansible managed hosts file\n127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4\n::1         localhost localhost.localdomain localhost6 localhost6.localdomain6\n\n192.0.2.46                 dualstack  dualstack.domain.tld\n2001:db8:192:2::46         dualstack  dualstack.domain.tld\n\n192.0.2.44                 ipv4only  ipv4only.domain.tld\n\n2001:db8:192:2::66         ipv6only  ipv6only.domain.tld\n```\n\n\n# Example Playbook\n\nJust specify the role:\n\n```yaml\n---\n- name: hosts-file\n  hosts: all\n  become: True\n\n  ## run role ##\n  roles:\n    - role: hosts-file\n```\n\n(It's preferable to specify the `hosts_hosts` variable in the inventory, host host or group).\n\nLicense\n-------\n\nApache 2.0\n\nAuthor Information\n------------------\n\nDaniel Shaw \\\u003cdaniel@techdad.xyz\\\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechdad%2Fansible-role-hosts-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechdad%2Fansible-role-hosts-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechdad%2Fansible-role-hosts-file/lists"}