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 user defined hosts and IP addresses to /etc/hosts #35

Open
blmhemu opened this issue Sep 20, 2021 · 0 comments
Open

Add user defined hosts and IP addresses to /etc/hosts #35

blmhemu opened this issue Sep 20, 2021 · 0 comments

Comments

@blmhemu
Copy link

blmhemu commented Sep 20, 2021

Add a default variable to let users set other hosts.
Currently, I am using the below code.

- name: Add hostname to /etc/hosts
  become: true
  lineinfile:
    dest: /etc/hosts
    regexp: "127[.]0[.]0[.]1.*"
    line: "127.0.0.1 localhost.localdomain localhost {{ ansible_hostname }} # added by ansible"
    state: present
    backup: yes

- name: Add Ansible inventory mappings to /etc/hosts
  become: true
  blockinfile:
    path: /etc/hosts
    block: |
      {% for host in groups['all'] %}
      {{ hostvars[host].ansible_host }} {{ host }}
      {% endfor %}

I am thinking of switching over to this role and would be great if this part can be handled in this role itself.

FYI, I understand that you guys use 127.0.1.1 for hostname. I'm fine with that approach too. Just need space for peer hosts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant