Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow manually defining user & hostname in callback plugin #496

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions ara/plugins/callback/ara_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@
ini:
- section: ara
key: record_controller
record_controller_name:
description:
- The name to use when recording the controller hostname.
- Defaults to the system hostname.
type: string
env:
- name: ARA_RECORD_CONTROLLER_NAME
ini:
- section: ara
key: record_controller_name
record_user:
description:
- Whether ara should record the user that ran a playbook
Expand All @@ -238,6 +248,16 @@
ini:
- section: ara
key: record_user
record_user_name:
description:
- The name to use when recording the user that ran a playbook.
- Defaults to the OS user which ran the playbook.
type: string
env:
- name: ARA_RECORD_USER_NAME
ini:
- section: ara
key: record_user_name
"""

# Task modules for which ara should save host facts
Expand Down Expand Up @@ -307,7 +327,9 @@ def set_options(self, task_keys=None, var_options=None, direct=None):
self.localhost_as_hostname = self.get_option("localhost_as_hostname")
self.localhost_as_hostname_format = self.get_option("localhost_as_hostname_format")
self.record_controller = self.get_option("record_controller")
self.record_controller_name = self.get_option("record_controller_name")
self.record_user = self.get_option("record_user")
self.record_user_name = self.get_option("record_user_name")

# The intent for the ignored_files default value is to ignore the ansible local tmpdir but the path
# can be changed by the user's configuration so retrieve that and use it instead.
Expand Down Expand Up @@ -826,6 +848,9 @@ def _get_localhost_hostname(self):
if not self.record_controller:
return hostname

if self.record_controller_name:
return self.record_controller_name

if self.localhost_as_hostname_format.startswith("fqdn"):
hostname = socket.getfqdn()

Expand All @@ -848,6 +873,9 @@ def _get_user(self):
if not self.record_user:
return user

if self.record_user_name:
return self.record_user_name
dmsimard marked this conversation as resolved.
Show resolved Hide resolved

try:
user = getpass.getuser()
except Exception:
Expand Down