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.

Would be nice to have a "host.fact.user" fact

See original GitHub issue

Is your feature request related to a problem? Please describe. Right now, if I want to get the user that is being used to connect to a given remote machine I have the following options:

  • Add group data that specifies the user for a given remote.
  • Use host.data.ssh_user (assuming an ssh connection).
  • Grab the host.fact.home fact and then split out the user.
  • Write a custom fact that does the above.

When running adhoc commands, the first two methods don’t work, and the last two methods require duplicate code in all operations that happen to need the “user,” which works but is not ideal.

Describe the solution you’d like It would be great to have a built-in host.fact.user. The host.fact.home fact is almost what I need, but falls short when it comes to running adhoc commands.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Fizzadarcommented, Nov 18, 2020

I like this idea; to get the current user right? Could be implemented by executing whoami, but that would mean calling it with sudo would return root (or the sudo_user), which I think is useful. Ie:

# deploy-no-sudo.py
print(host.fact.user)  # SSH user

vs:

# deploy-with-global-sudo.py

SUDO = True
print(host.fact.user)  # root

This would be the same behaviour we have the host.fact.home. I think to get the SSH user (or winrm user, etc, etc) that is something specific to the connection type, and makes sense to be retrieved from there.

0reactions
Fizzadarcommented, Dec 9, 2020

Now released in v1.3!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ansible Facts and How to use them - Ansible Variable list
In this post, we are going to see, What is ansible facts (or) playbook variables and how to use these facts various types...
Read more >
Here's how to access facts from other hosts (advanced feature)
first calling the dbservers to load up their data. I suspect most people won't need this, but the fact that we can do...
Read more >
facts and magic variables — Ansible Documentation
Variables related to remote systems are called facts. With facts, you can use the behavior or state of one system as configuration on...
Read more >
ansible set global fact · Issue #16049 - GitHub
Is there any way of making the set_facts global for all hosts, so that it sets the fact once and use the same...
Read more >
4. Variables and Facts - Ansible: Up and Running [Book]
However, if the task fails, then Ansible will stop executing tasks for the failed host. We can use the ignore_errors clause, as shown...
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