Skip to content

Commit

Permalink
Allow manually defining user & hostname in callback plugin
Browse files Browse the repository at this point in the history
In some environments (e.g. containers), the user and hostname detected from the OS might not be relevant or useful. This change allows the user to pass in customized values for these attributes which override the automatic detection.
  • Loading branch information
phemmer authored and dmsimard committed Sep 3, 2023
1 parent 30ff2ab commit 3a180df
Showing 1 changed file with 28 additions and 0 deletions.
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

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

0 comments on commit 3a180df

Please sign in to comment.