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

Are defaults applied per file or globally? #52

Open
davidpelaez opened this issue Sep 8, 2015 · 12 comments
Open

Are defaults applied per file or globally? #52

davidpelaez opened this issue Sep 8, 2015 · 12 comments

Comments

@davidpelaez
Copy link

Hi,

I was wondering if the defaults section is global when used inside an included file. For instance I have a production.yml file included in the main config, if I put a global section there will it overwrite or merge the global defaults in the top config file? Or will it apply "globally" to the configuration file where it's written? I assume it's global and I would instead have to use a host definition and then inherit, but just checking for clarity. :)

Thanks!

@moul
Copy link
Owner

moul commented Sep 8, 2015

Actually the defaults is fully global and I think it should stay like this
However, if it may make things easier or more powerful, I can add a new per-file file-defaults section


FYI, my current personal workflow about includes is quite simple:

  • a ~/.ssh/assh.yml file with defaults, includes
  • 1 ~/.ssh/assh.d/{group}.yml per group/category of hosts (school, work, home, tmp)

@moul moul self-assigned this Sep 8, 2015
@davidpelaez
Copy link
Author

That sounds like a good flow but it has the downside of listing inheritance as a host. Maybe make them templates instead of hosts so they don't get listed as such? file-defaults also works like a nice alternative if you comment the specific flow in more detail. The templates has the advantage of sharing across files.

@moul
Copy link
Owner

moul commented Sep 8, 2015

What do you think about:

  • add templates -> same as host, but not listed, only used by inheriting
  • no change to defaults
  • a new per-file file-templates which is not a template itself, but a list of templates to apply to hosts on the file

i.e:

~/.ssh/assh.yml

defaults:
  ...

includes:
- ~/.ssh/assh.d/*.yml
- /etc/assh.yml

~/.ssh/assh.d/templates.yml

templates:
  idrsa-hosts:
    IdentityFile: ~/.ssh/id_rsa
  bob-hosts:
    User: bob
  sam-hosts:
    User: sam
    Port: 23
  controlmaster-hosts:
    ControlMaster: auto
    ControlPath: ~/tmp/%h-%p-%r.sock
    ControlPersist: yes

~/.ssh/assh.d/bob.yml

file-templates:
- bob-hosts
- idrsa-hosts

hosts:
  abc-server:  # inherits from controlmaster-hosts, bob-hosts, idrsa-hosts
    HostName: 1.2.3.4
    Inherits:
    - controlmaster-hosts
  def-server:  #inherits from bob-hosts, idrsa-hosts
    HostName: 5.6.7.8

~/.ssh/assh.d/sam.yml

file-templates:
- sam-hosts
- idrsa-hosts

hosts:
  ghi-server:  # inherits from contromaster-hosts, sam-hosts, idrsa-hosts
    Inherits:
    -  controlmaster-hosts
    HostName: 2.3.4.5
  jkl-server:  # inherits from sam-hosts, idrsa-hosts
    HostName: 6.7.8.9

~/.ssh/assh.d/other.yml

hosts:
  mno-server:  # inherits from idrsa-hosts
    Inherits:
    - idrsa-hosts
    HostName: 3.4.5.6
  pqr-server:  # no inheritance
    HostName: 7.8.9.10

@davidpelaez
Copy link
Author

I think file-templates as an application procedure is slightly unclear. How I see it templates and file-templates are definition keys with different scopes. defaults and file-defaults could be appliers with different scopes. This allows for locally scoped templates as well as their applications. Continuing with your examples:

~/.ssh/assh.d/sam.yml

# define file specific templates
file-templates:
  shared-template:
    User: file-specific-user

# apply it together with other templates
file-defaults:
  Inherits:
  - sam-hosts
  - idrsa-hosts
  - shared-template

hosts:
  ghi-server:  # inherits from contromaster-hosts, sam-hosts, idrsa-hosts _&_ shared-template
    Inherits:
    -  controlmaster-hosts
    HostName: 2.3.4.5
  jkl-server:  # inherits from sam-hosts, idrsa-hosts _&_ shared-template
    HostName: 6.7.8.9

The only important think to consider is that the rules of precedence should be very clear. For instance if two templates define User then it should be clear how assh will choose the one to use.

What do you think?

@moul
Copy link
Owner

moul commented Sep 8, 2015

I also prefer your file-defaults approach to define Inherits for the file hosts

But I'm more to keep templates globally scoped, it will be a real pain to manage privacy of templates in my structures, it may also be useful later if I add some helpers to list the templates or to create host graphs for instance
I prefer to manually prefix a template like this

# define prefixed templates (the templates may be moved in other files too)
templates:
  sam-shared-template:    # manually prefixed template, but still shared globally
    User: file-specific-user

# apply it together with other templates
file-defaults:
  Inherits:
  - sam-hosts              # global template from another file
  - idrsa-hosts            # global template from another file
  - sam-shared-template    # global template from this file

hosts:
  ghi-server:  # inherits from contromaster-hosts, sam-hosts, idrsa-hosts _&_ sam-shared-template
    Inherits:
    -  controlmaster-hosts
    HostName: 2.3.4.5
  jkl-server:  # inherits from sam-hosts, idrsa-hosts _&_ sam-shared-template
    HostName: 6.7.8.9

@davidpelaez
Copy link
Author

You mention that the templates can be moved to another file. So if I can have multiple definitions of templates then it works great and using prefixes for personal namespacing is good. As long as I can have templates per file it sounds good to me. This is important because that way I can take the production.yml and then share it with my team for example and I can have all I need in a single file.

@moul
Copy link
Owner

moul commented Sep 8, 2015

Yes, every sections may exists in any files and multiple times

I will add an exception: the file-defaults section which will be (for now) the only scoped section

@davidpelaez
Copy link
Author

👍

moul added a commit that referenced this issue Sep 26, 2015
moul added a commit that referenced this issue Sep 26, 2015
@moul
Copy link
Owner

moul commented Sep 26, 2015

Templates are now handled, I still need to handle the file-defaults section

@davidpelaez
Copy link
Author

Great, let me know if you want some testing once everything's merged. I'll be happy to take a look locally to see how things work. Cheers.

@moul
Copy link
Owner

moul commented Sep 28, 2015

Ok, thanks :)

@moul moul added this to the Proposal milestone Mar 21, 2016
@moul moul added the freeze label Dec 6, 2016
@Falkor
Copy link

Falkor commented Mar 12, 2017

+1

This would be excellent to shorten the rules and subconfigs!

Any chance to have that released soon?

@moul moul removed their assignment Sep 18, 2017
@moul moul removed freeze labels Nov 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants