Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Add ssh_private_key configuration option #38

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions runner_service/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def __init__(self, mode='dev'):
self.runner_cache_size = 5
self.debug = Config.MODES[mode].get("debug", True)

# Path to custom ssh key, by default project/env/ssh_key is used
self.ssh_private_key = os.path.join(
self.playbooks_root_dir,
"env/ssh_key"
)

# expiration period in years for the self-signed cert that we generate
self.cert_expiration = 3

Expand Down
5 changes: 5 additions & 0 deletions runner_service/services/playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ def start_playbook(playbook_name, vars=None, filter=None, tags=None):
"{}".format(configuration.settings.target_user))
cmdline.append("--user {}".format(configuration.settings.target_user))

if not configuration.settings.ssh_private_key.endswith('env/ssh_key'):
logger.debug("Run the playbook with a private key override of "
"{}".format(configuration.settings.ssh_private_key))
cmdline.append("--private-key {}".format(configuration.settings.ssh_private_key))

if cmdline:
commit_cmdline(cmdline)

Expand Down
3 changes: 1 addition & 2 deletions runner_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ def ssh_connect_ok(host, user=None):
else:
user = getpass.getuser()

priv_key = os.path.join(configuration.settings.playbooks_root_dir,
"env/ssh_key")
priv_key = os.path.join(configuration.settings.ssh_private_key)

if not os.path.exists(priv_key):
return False, "FAILED:SSH key(s) missing from ansible-runner-service"
Expand Down