Alternative to ansible implicit localhost host
See original GitHub issueAnsible has implicit localhost host which you can use as a target for your tasks, or use:
delegate_to: localhost
run_once: true
Currently nornir does not have this concept (but it also does not ship the code to execute remotely) and majority of tasks work on localhost and some establish network connection.
It is a little bit confusing.
E.g., nornir-tools
has an example of doing network configuration backup. It runs napalm_get
and write_file
on a group of networking devices.
But what does it really mean that to run the task write_file
on a number of networking devices without digging a lot into doc? Does it mean I will save the file on the networking device filesystem or locally? I need to check docs or sometimes source code to be sure.
Example use-cases associated with localhost:
- Do something strictly on localhost, like execute shell command, save file, etc.
- Generate some config file based on variables of another group of hosts (for example, take all existing hosts with their IPs and MACs and use Jinja to generate dhcpd.conf or other file to be consumed by DNS service)
- Do API calls
- Modify variables for the existing hosts (mixed feelings here, could be
Function
, could beTask
)
I don’t have a good solution in mind for this. May be something like nornir_runner.local_run
or nornir_runner.run(local=true)
instead of nornir_runner.run
? This would allow localhost directly access target’s vars.
May be the Task itself must be also LocalTask
which could be a subclass of Task
.
I also feel that having some kind of implicit Host: localhost could be helpful to keep specific key-value pairs on the fly that don’t belong to any other Host or Group
What are your thoughts about this?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
I am definitely not saying that ansible’s approach is good, but I still feel that the current abstraction is not intuitive.
@dbarrosop On slack you mentioned that you create empty
localhost
in your inventory to do host-agnostic tasks. Do you think we could add implicitlocalhost
to the inventory? Or it would be too muchmagic
?