using includes in a hosts file - include

Can I do something similar to apache Include with my hosts file?
/etc/hosts
127.0.0.1 localhost
Include /something/test-hosts
/something/tests-hosts
127.0.0.1 test.local

So to answer the question, no you cant use include in a hosts file

Related

How do I mention duplicate host ip in Ansible inventory file

I have the below entry in the host file
cat server.hosts
[mum_servers]
10.12.34.213 USER=user1
10.12.34.213 USER=root
[all_hosts:children]
mum_servers
Below is how I run my playbook where I specify hosts as all_hosts
ansible-playbook -i server.hosts test.yml
However the playbook runs 10.12.34.213 only once and not twice as mentioned in the hosts file.
I understand that Ansible treats duplicate entries for hosts as a single entry, however can you please suggest how can I change my server.hosts file to make 10.12.34.213 run twice first with user1 and then with root ?
You have to create different hosts using aliases
my_host_as_user1 ansible_host=10.12.34.213 USER=user1
my_host_as_root ansible_host=10.12.34.213 USER=root

Ansible inventory: how to identify hosts by port

I have set 2 servers for testing purposes, which are behind a NAT network. So I configured port forwarding to SSH port for both of them.
My inventory file looks like this:
[webservers]
example.com:12021
example.com:12121
[webservers:vars]
ansible_user=root
ansible_ssh_private_key_file=~/test/keys/id_ed25519
But Ansible only identifies one of them(whichever is first in the list). My "hack" to run ansible-playbook commands on both of them is by changing the order in the hostlist, and running the playbook twice.
So, is there any way to identify the hosts by port number, and not by hostname?
Thanks in advance.
Use any label you like:
[webservers]
server1 ansible_host=example.com ansible_port=12021
server2 ansible_host=example.com ansible_port=12121

cannot add new host to mac OS X

I am trying to add new entry to the /etc/hosts in mac os (el Capitan)
how ever when I try to ping this entry , I am getting error of not resolved
there is no nsswitch file
what am I missing?
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
local.datafabric.io localhost
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
In the man page for the hosts file
man hosts
the syntax is explained:
IP_address canonical_hostname [aliases...]
so, if you want to add the name local.datafabric.io as an alias for localhost (127.0.0.1), the line should look like this:
127.0.0.1 localhost local.datafabric.io
man is your friend.
You will probably also want to flush your dnscache. The correct commands for that are depending on the actual version of MacOS.

ping: cannot resolve localhost: Unknown host OS X

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
This is my /etc/hosts file but it's really strange failure to ping and cannot resolve localhost.
It's work well like ping gonjay when I add
127.0.0.1 gonjay
to my hosts file.
I fixed it by making sure that hosts file used Unix line endings (I used Sublime Text for this)
I have solved the problem by restoring my Hosts file (it was empty):
But before, you have to check your hosts file.
cat /etc/hosts
If nothing is shown, that means your hosts file is empty.
Then just copy and paste this over the existing hosts file then save it as plain text to restore it.
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
If your hosts file is not empty, your can try to delete it and add it again with this lines.
Probably will help for those who don't know how make Unix line endings
brew install dos2unix
sudo dos2unix -c mac /private/etc/hosts
That will convert your perfectly fine hosts file to UNIX encoding.

Windows hosts file

What's the difference between these lines:
::1 localhost
...and
127.0.0.1 localhost
in Windows hosts file?
Initially I had the line of the first kind in my hosts file and typing localhost in the browser led me to 127.0.0.1. Then I didn't use localhost prompt in the browser for some time, and when I needed to use it again it just didn't work. I changed the first line form the second one in my hosts file and it worked. Why could that happen?
::1 is IPv6.
127.0.0.1 is IPv4.
::1 is IPv6
127.0.0.1 is IPv4
I guess you disabled IPv6 in between tests?
The former, "::1" is IPv6 compressed syntax for the localhost. It is equivalent to 127.0.0.1. Did you disable IPv6 support in your OS or network adapter? Maybe that's why it stopped working.
I believe ::1 is the IPV6 notation of 127.0.0.1.

Resources