Skip to content

Commit c03ed0d

Browse files
Merge pull request #145 from naveenkandakur/dev-collection
Support for ANSIBLE_PRIVATE_KEY_FILE env variable
2 parents 2dfa076 + 8c42b0f commit c03ed0d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ This repository contains some example best practices for open source repositorie
4545

4646
- Requires Python 3
4747
- lxml
48+
49+
### Supported Environment Variables
50+
The following environment variables are supported for configuring SSH behavior in Ansible. No other Ansible parameters apply for these actions:
51+
- ANSIBLE_PRIVATE_KEY_FILE = Specifies the absolute path to the SSH private key file. This enables passwordless SSH connections
52+
- ANSIBLE_HOST_KEY_CHECKING = Controls whether host key checking is performed during SSH connections. Supported values: False, false, No, no Setting this disables StrictHostKeyChecking.
53+
4854
## Resources
4955

5056
Documentation of modules is generated on [GitHub Pages][pages].

plugins/module_utils/hmc_cli_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ def execute(self, cmd):
4040
stdout = None
4141

4242
host_key_ignore = ''
43+
ssh_private_key_file = None
4344
# This env 'ANSIBLE_HOST_KEY_CHECKING' only will work in case if it is set as environment variable
4445
# All other options like from ansible config file or inventory file wont work
4546
if os.environ.get('ANSIBLE_HOST_KEY_CHECKING') in ['False', 'false', 'FALSE', '0', 'no', 'No', 'NO']:
4647
host_key_ignore = ' -o StrictHostKeyChecking=no '
4748

49+
# This env 'ANSIBLE_PRIVTAE_KEY_FILE' takes the input of ssh private key file with absolute path
50+
if os.environ.get('ANSIBLE_PRIVATE_KEY_FILE'):
51+
ssh_private_key_file = os.environ.get('ANSIBLE_PRIVATE_KEY_FILE')
52+
4853
logger.debug("COMMAND: %s", cmd)
54+
4955
if self.pwd:
5056
ssh_hmc_cmd = "sshpass -p '{0}' ssh '{1}'@{2} {3} '{4}'".format(self.pwd, self.user, self.ip, host_key_ignore, cmd)
57+
elif ssh_private_key_file:
58+
ssh_hmc_cmd = "ssh -i '{0}' '{1}'@{2} {3} '{4}'".format(ssh_private_key_file, self.user, self.ip, host_key_ignore, cmd)
5159
else:
5260
ssh_hmc_cmd = "ssh '{0}'@{1} {2} '{3}'".format(self.user, self.ip, host_key_ignore, cmd)
5361

0 commit comments

Comments
 (0)