Basically, I want one place to specify a default user, port, hostname, and identity file for each server.
I have no playbooks, so they can be taken out of the equation for now.
To get a ‘/usr/bin/whoami’ command to return ‘root’ for all servers, I need to:
-
Write hostnames (ugly EC2 versions) to my inventory file (cannot use ~/.ssh/config Host aliases)
-
Specify the user ‘ubuntu’ on the command line (can’t add that to the inventory file)
-
My ~/.ssh/config file has the identity key because that also cannot be specified in the inventory file
-
I need to have double definitions for each server in my ~/.ssh/config file (1 with Host alias, 1 with Host being the hostname) because ansible does not lookup by Hostname, it looks up by Host
-
Add “-s” on the command line because that cannot go in the inventory file
If any of those points are wrong, please let me know, as I am trying to understand the best way to set it up.
Other comments inline:
Since ansible is all about SSH, I think there should be a clear waterfall (inheritance) for SSH configuration.
Waterfall and inheritance mean other things. I think you mean “order of precedence”.
Yes “order of precedence” is what I mean
From what I can see, SSH config can come from:
-
ansible.constants (default values)
-
inventory file
-
~/.ssh/config
-
playbook
-
command line
Overrides actually do this:
- the defaults mechanism is SOURCE CODE and basically just uses the default SSH port. Not remotely strange
No, not strange at all, but it does require a code change to make the default user something else.
- the command line on the devel branch has no options to control the port anymore, because we want people to keep that in inventory. The simple INI format takes a host:port, for instance, which is pretty simple.
But the user can still be specified on the command line.
- the playbook will override the inventory file if you put a port in there, but it’s really the least ideal place to put a port, as you’ll end up repeating yourself, and we should basically remove this from examples now
Agreed, and repetition is what I am trying to avoid with inventory vs ssh/config
- if there is a port setting in the SSH config, or a key pair setting, those always win, but ~/.ssh/config is not required.
There is no clear order or inheritance for these. Currently
It may not be clear, but there is an order.
I believe there should be a clear hierarchy of what location overrides what. I propose the order is the one above, where command line is king. This allows the ~/.ssh/config file to be fully utilized, while allowing playbooks and the command line to overwrite values as needed.
There’s already an order.
The SSH config file can already be fully utilized for setting the port or key pair, so I don’t understand what you are requesting.
It is not fully utilized because it does not use the username nor host/hostname. Only 2 values are hand picked. There is a lot more value in .ssh/config.
It should not be used to set the user because you can have perfectly valid reasons for logging
into a host as multiple users.
Yes, I totally agree, which is why specific playbooks can overwrite the default values that the combination of ~/.ssh/config and the inventory file provide.
Also ssh_config makes a distinction between Host and Hostname. This is great for creating human-friendly aliases, and it would be great if the inventory file could merge with ~/.ssh/config. Currently, this distinction is not in ansible, though I would like it to be. Perhaps reading ~/.ssh/config should be part of the inventory file code?
I think the group designations are quite important and think that just further confuses things.
How so?
In my example, the inventory file is clear because it uses the human friendly names (Host instead of Hostname from ~/.ssh/config).
Background on my use case:
What are your thoughts and use cases? Does the above proposal work?
I’m interested in hearing what is currently broken and impossible for you, right now, before we discuss any idea of change. It’s easier to understand the problem from the problem rather than a proposed change or solution.
So far I’m mostly hearing that things are unclear, which I think are explained above.
Top of post - default user and identity file per server.
Added bonus if Host to Hostname mapping allowed.
Further down the track, I would love to have the inventory management be a module/plugin. I can see value in having the inventory coming directly from the EC2 API, or Rackspace Cloud API, but that is for another day
No, it’s already today. This is what the external inventory stuff does if your inventory file is an executable script. This is covered in the docs and there’s an example of how to do it with the Cobbler API.
So you can source groups and variables from anywhere, basically. This was modeled more or less directly on puppet’s external nodes concept, which many people may be familiar with.
Awesome… I didn’t see this before. Do you know if anyone is working on an EC2 version?
I am happy to volunteer to make the changes in a separate branch once a decision is made.
I don’t think I’ve agreed to any changes yet I need to be convinced something is not possible first.
Exactly, but rest assured when/if we do, you are not the only one doing the work