Skip to content

Instantly share code, notes, and snippets.

@mpdehaan
Created January 30, 2019 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mpdehaan/7ce983b5f8edea5f391d75f378dbaa03 to your computer and use it in GitHub Desktop.
Save mpdehaan/7ce983b5f8edea5f391d75f378dbaa03 to your computer and use it in GitHub Desktop.
# push mode will look about like this:
if __name__ == '__main__':
inventory = TomlInventory("inventory/inventory.toml")
inventory.ssh([WebServerRole(), AnotherRole() ])
# if you want to run check mode, you can still access it, though it is not the default:
inventory.ssh([WebServers(), AnotherRole() ], check=True)
# if you want --check or --apply to be CLI options, it looks like the lines below
# if you don't supply --check or --apply the script will *not* activate this way
if __name__ == '__main__':
inventory = TomlInventory("inventory/inventory.toml", use_cli=True)
inventory.ssh([ WebServers(), AnotherRole() ])
# "ssh" is the name of a connection plugin. You will be able to add your own plugins.
# local mode is basically an inventory of just one host, with only one plugin
if __name__ == '__main__':
local = Local(use_cli=True)
local.run([ WebServers(), AnotherRole() ])
# the return structure from ".run" will be an object that contains meaningful data about the results of each
# host, and in Jupyter context should be some interesting widget, or have some helper functions to show it as
# a widget (TBD)
@mpdehaan
Copy link
Author

Roles can still be parameterized by passing keyword arguments to their constructors.

@mpdehaan
Copy link
Author

mpdehaan commented Jan 30, 2019

I may need to figure out how to return a object that can live update, which may cause some changes to the above.

Like proc = local.prepare(...) / proc.run() ... and maybe some magic to enable the CLI callbacks in that mode.

TBD.

@mpdehaan
Copy link
Author

Controls about the degree of parallelism enabled should be key=value arguments to the inventory object, which all will inherit from a base inventory class.

@mpdehaan
Copy link
Author

for readability:

local.run([ WebServers(), AnotherRole() ])

should be equivalent to:

local.run(WebServers(), AnotherRole())

@mpdehaan
Copy link
Author

mpdehaan commented Jan 30, 2019

I considered role.push(inventory). This is a bit more clear, and honestly, what this allows is:

webservers = inventory.filter_groups('webservers')
webservers.ssh(role)

This is much more explicit, and eliminates the code in the role that says where it goes, and this is probably a good idea to ax.

@mpdehaan
Copy link
Author

In doing the above, this would also mean:

local.run(role)

@mpdehaan
Copy link
Author

mpdehaan commented Jan 30, 2019

.ssh would remain a method on an inventory, as ".filter_groups" returns a subset of inventory (same with filter_hosts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment