question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alternative to ansible implicit localhost host

See original GitHub issue

Ansible 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 be Task)

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:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dmfigolcommented, Jul 3, 2018

I am definitely not saying that ansible’s approach is good, but I still feel that the current abstraction is not intuitive.

0reactions
dmfigolcommented, Jul 20, 2018

@dbarrosop On slack you mentioned that you create empty localhost in your inventory to do host-agnostic tasks. Do you think we could add implicit localhost to the inventory? Or it would be too much magic?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A journey with Ansible 2.12, implicit localhost and python ...
I recently upgraded to Ansible 2.12 and a couple of my playbooks stopped working. This seems to be down to a change in...
Read more >
Implicit 'localhost' - Ansible Documentation
When you try to reference a localhost and you don't have it defined in inventory, Ansible will create an implicit one for you.:...
Read more >
How to build your inventory - Ansible Documentation
Here are three options beyond the /etc/ansible/hosts file: - You can create a directory with multiple inventory files. See Organizing inventory in a...
Read more >
Frequently Asked Questions — Ansible Documentation
How do I loop over a list of hosts in a group, inside of a template? How do I access a variable name...
Read more >
Working with dynamic inventory - Ansible Documentation
Implicit use of OpenStack inventory script ... If your Ansible inventory fluctuates over time, with hosts spinning up and shutting down in response...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found