edited hosts file and now localhost doesnt work - osx-mountain-lion

So I was trying to add an entry to my hosts file so that my testing environment would be at local.domain.com instead of localhost.
Now that I made edits, nothing is working, including localhost. I read somewhere that it has something to do with editing it in certain programs giving weird errors so to open it in something else and save it. I tried that and still nothing.
Is there any way i can just 'reset' this file? Or any ideas anyone has?

did You try this:
127.0.0.1 localhost
::1 localhost

Related

Ansible dynamic inventory service concept

I've been reading the ansible documentation on how to create a dynamic inventory. From what I understand I have to provide a json that is capable of outputing host_vars and group_vars.
With that in mind, how would I go about extending the group_vars and host_vars concepts to include the definition of service ?
In essence, my "end goal" would be to have something that allows me to define:
Host A has services A B C that would then turn into the corresponding host and group vars.
What is the best way to approach this?
I have been thinking about maybe a database but I'm not quite sure on how to propperly abstract the service concept.
Thanks in advance for any help
I cannot give you all your answers, I just started using Ansible four weeks ago. However, I have successfully integrated dynamic inventories. Here's what I can share: (extrapolate for your setup, I'm in a RHEL shop, using 6.9 and 7.4)
By default, ansible looks for your inventory in a file found at /etc/ansible/hosts The default format for that file is (I believe) INI format.
[servers]
server-1
server-2
[labhosts]
labhost-1
labhost-2
[localhost]
127.0.0.1
/etc/ansible/ansible.cfg will allow you relocate your inventory file/directory if needed. For now, my comments will assume no changes from the default
The example above is static inventory. You can move your /etc/ansible/hosts file aside, then do: mkdir /etc/ansible/hosts/
mv your hosts file, into /etc/ansible/hosts/hosts It's OK, to have static inventory files inside your dynamic directory (for now) So the beauty is, you can still use static inventory, it just now lives in /etc/ansible/etc/ <-- directory There is nothing special about the static filename. It can be any name, however some chars are not valid as part of the static file names.
To use dynamic inventory, you now only need to put into the /etc/ansible/hosts/ directory, executable scripts that pull your hostnames from some external database. AND, this is the KEY part, the output (the stdout) of that script MUST output in JSON format.
When ansible looks for your inventory files, it will "see" that /etc/ansible/hosts/ is a dir and then look in there for scripts. When you run a play or playbook, it will execute the script, and use the JSON output as your host targets of your play.
Now, I'm no JSON expert, but here's what works for me. The syntax of the JSON is like this: {"GROUPNAME":["HOST1","HOST2","HOST3",]}
So the entire string is bounded by left and right curly braces. The first field is the quoted groupname, separated by a colon, then the comma delimited list of quoted hosts, bounded by left and right square brackets.
In my environment, we have a perl script, and based on switch parameters, pulls lists of hostnames. We recently modified the perl script, using print statements to generate the JSON output. There is a JSON: perl module, but we didn't find it necessary to use, as formatting the output using print was sufficient. As for the groupname, we also "built" that groupname from the switch settings on the perl script.
So using my INI inventory example above, the JSON output would be something like this: {"servers":["server-1","server-2",]}
Note1: One quirk that I've learned, if you only have ONE host, it must be terminated with a comma. There's a reason, I'm not sure I can explain it. When we are generating our JSON output, we add a comma, regardless of the number of hosts, and it just works.
Note2: I realize this is not real JSON output, but it's working for our needs.
In your playbooks, you would put - hosts: all or - hosts: your_group_name
I usually just put - hosts: all, then limit using -i option and/or "--limit=hostname"
"-i", narrows your inventory to just the static or dynamic generated list
--limit=hostname where "hostname" is one of the subset of -i output.
Consider this command: ansible all -m ping
This will ping all hosts in your entire inventory. Both static and dynamic
ansible all -m ping -i servers
This will ping all hosts in your servers group
ansible all -m ping -i server --limit=server-1
This will ping just the one host, "server-1"
Using --limit= is great for testing plays or playbooks
When moving on to playbooks, you specify the hostlist, in the playbook.
Then you only need to add limits as needed, on the command line.
Good luck!

How to ignore my inventory option in .ansible.cfg?

I've double-checked that Ansible is reading my .ansible.cfg file (it is).
However, if I use the setting:
inventory = /my/local/inventory
I keep getting the error message No hosts matched if I ignore the -i option when running ansible.
I've tried ansible -vvv but that hasn't shed any light.
I've also looked at https://github.com/ansible/ansible/issues/11907 and checked there aren't any ENV variables set.
Any other suggestions?
You said .ansible.cfg which is the file it will search for in your home directory. If you are expecting an Ansible configuration for the current directory, make sure it is called ansible.cfg. See the docs for more information on search order for Ansible config.

custom url instead of having localhost

I have a folder called example inside htdocs in XAMPP , so I access my url with localhost/example/ . How can I have just example/ instead of localhost/example/ when I type my url ? Thanks in advance!
I've tried editing DocumentRoom in apache htdocs and it didn't work...
I'm not sure if that helps you, but you have to set the html root into your example folder to be able to use localhost/ only. Maybe you can move all contents of the example folder to the parent directory and try again.
If you want to use a real URL like example.com/ instead of localhost/ you can edit your hosts file
sudo nano /etc/hosts
and add the following lines to the end:
127.0.0.1 www.example.com
127.0.0.1 example.com

nginx home environment variable?

I have some nginx config in a repo, and the application root is sometimes different on different machines and setups:
server {
listen 80;
server_name admin.triface.local;
root /Users/xxxxxx/Sites/triface-admin/public;
index triface.html;
}
I want to set a variable somewhere (like an bash environment variable or equivalent) that lets me avoid hardcoding the server root. It seems like this should be straightforward, but I can't find anything on it. Any clues?
So the answer is, there isn't any! Intentionally! And once I read the reasoning, it actually made sense. Though it is a bummer I can't do local nginx installs to people's $HOME dir, but I can live with that.
See this stackoverflow answer:
How do I pass ImageMagick environment variables to nginx mongrels?
Sure:
set $homedir /Users/xxxxxx/Sites/triface-admin/public;
Then just call $homedir

vhosts not working on windows 7 using wamp

i'm having trouble setting up vhosts on windows 7. i'm running wamp.
my host file includes:
127.0.0.1 local.tribune.com
i've included httpd-vhosts.conf from within my httpd.conf.
my httpd-vhosts.conf includes:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/Users/Name/My Documents/the tribune/website/local.tribune.com/"
ServerName local.tribune.com
</VirtualHost>
here's the weird thing..if i remove the 'My ' from the DocumentRoot, then going to localhost in a browser works and i can see phpmyadmin, but i can't see the contents of the directory because the path is incorrect. but soon as i put that 'My ' in the path, the wamp icon never goes white (it stays yellow), and i can't reach localhost or local.tribune.com.
soon as i remove the 'My ' again, localhost will work again.
i've seen multiple posts around this issue on wampserver.com and elsewhere, but none of them answered or resolved. most that are resolved are basic issues like not including or having deleted httpd-vhosts.conf, missing characters, etc.
Its never a good idea to have a space in your directory path. URL Encoding interprets it as: "%20%". I would suggest placing your website files on D:/websites/local.tribune.com
you can read more about URL Encoding here
Hope that helps
solved it. was close before, but just missed it.
in windows 7, the path is NOT:
c:/Users/Name/My Documents/the tribune/website/local.tribune.com
but is actually:
c:/Users/Name/Documents/the tribune/website/local.tribune.com
to prove this, click at the end of a path in a windows explorer window, and the full path is displayed in plain text.
also, just because i've seen some disagreement online, in my experience:
the drive letter is case insensitive
the slashes can go either way
trailing slashes have no effect
path names CAN have a space in them

Resources