ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
93 stars 19 forks source link

platforms: automatically group hosts and aply sane defaults per platform (windows, linux distro, network OS, etc) #77

Open bcoca opened 7 years ago

bcoca commented 7 years ago

Proposal: platforms

Author: Your Name <@yourGHid> IRC: handle (if different)

Date: 2017/xx/xx

Motivation

Allow quicker setup to users by defining 'prexisting' platforms/groups that will configure a set of connection variables 'known to work' in conjunction.

Solution proposal

A default set of groups from an 'internal inventory' that are available for use any inventory

# lib/ansible/config/platform.yml
all:
  children:
    ansible__windows_platfrom:
       vars:
          ansible_connection: winrm
          ansible_shell_type: powershell
          ansible_become_method: runas
          ansible_remote_tmp: C:\temp
          ansible_gather_facts_modules: ['win_setup']  # doesn't exist, but PR that allows this in queue
          ansible_module_exts: ['.ps1', '.exe', '.bat', '.cmd']  #  does not exist, but easy to add

    ansible_sunos_platfrom:
       vars:
          ansible_remote_tmp: $HOME/.ansible/tmp  # adding in 2.5

    ansible_aix_platfrom:
       vars:
           ansible_world_readable_tmp: True  #  adding in 2.5

    ansible_ios_platform:
        vars:
            ansible_connection: local
            ansible_persistent=True
            ansible_gather_facts_modules:
                - netconf_facts
                - ios_facts

So users can just assign hosts to these groups in any other inventory and the vars/settings will be applied to those hosts.

Anything else?

This can work well with a persistent fact cache and the contstructed inventory plugin and/or some 'pre detection' to classify the hosts to make new setups/adding newly provisioned hosts in a very quick way to inventory and start working with Ansible

alikins commented 7 years ago

use case?

Are there existing issues that would be resolved by this?

alikins commented 7 years ago

'ansible_platform' would be a fact?

Would there be a 'platform' keyword for plays/tasks ?

Are the platform definitions built from config? Could playbooks or roles define them? Could playbooks or roles extend or override them?

How would someone share a platform definition?

Can the platform definitions include variables and templating?

Whats the var precedence?

alikins commented 7 years ago

What all can a platform definition set? Only connection variables?

bcoca commented 7 years ago

use case? Are there existing issues that would be resolved by this?

No open issues, as 'motivation' states this just makes it easier for users to get started with Ansible

'ansible_platform' would be a fact?

No, we might need to change the name to disambiguate ...but it can be used with facts/inventory data to autoassign

Would there be a 'platform' keyword for plays/tasks ?

No, it fits more with inventory than with play objects.

Are the platform definitions built from config? Could playbooks or roles define them? Could playbooks or roles extend or override them?

yes ... possibly, not sure why they would need to expand them, they are mostly intended for quick setup to be able to have hosts targeted with the correct connection/plugins/etc

How would someone share a platform definition?

depends on implementation .. but currently we could already do this by defining them as a group with associated variables.

Can the platform definitions include variables and templating?

I think the above already answers that

Whats the var precedence?

depends on implementation, but mostly they should be pre/post inventory vars

What all can a platform definition set? Only connection variables?

depends on implementation, it is geared mostly to connection variables ... not sure what else would make sense under these, but should be easy enough to expand.

nitzmahone commented 7 years ago

I have some concerns with implementing this simply as built-in groups with no other changes:

I think controlling all this stuff via vars makes more sense than using a simple group membership- the number of exceptions we need to make to current group behavior for robustness makes it feel like maybe groups aren't exactly the right thing for this.

nitzmahone commented 7 years ago

It could probably be argued that platforms should be composable like normal groups (eg, platform: windows + platform: server_2008r2), but I think we're getting into a major new precedence headache there.

bcoca commented 7 years ago
nitzmahone commented 7 years ago

Yeah, sounds like there are decent workarounds to everything except the "can be a member of multiple platforms" issue. I'm not sure that issue is worth going a harder route or not. I haven't floorplanned a solution for "platform-as-a-var" yet, but I suspect it will be significantly gnarlier than this. If we can agree on the "one platform group per host" restriction, I think I'd be willing to call it "good enough". I also think this would work well enough for what networking needs, but I'd want to kick that around with @Qalthos and maybe @privateip a bit before making that call.

jhawkesworth commented 6 years ago

@bcoca I understand this is a readmap item for ansible 2.7 so I hope this comment is still timely.

This may be scope creep but I just noticed yesterday that the default module for ad-hoc ansible commands does not appear to be sensitive to the connection in use, meaning you can't use command lines like

ansible windows_host -a 'dir'

(Just to be clear, running ansible windows_host -m raw -a 'dir' does what you would expect though).

So would it possible as part of this to specify default module - or would this be a separate change to make default module a property of the connection plugin?

bcoca commented 6 years ago

@jhawkesworth any of the general configuration items is available, so it does seem to make a lot of sense to change to win_command when platform == windows cc @nitzmahone