xlab-si / xopera-opera

xOpera orchestrator compliant with TOSCA YAML v1.3 in the making
https://xlab-si.github.io/xopera-docs/
Apache License 2.0
35 stars 14 forks source link

Introduce an environment variable for ssh key(s) in the xOpera's Ansible executor #57

Closed anzoman closed 4 years ago

anzoman commented 4 years ago

Description

xOpera orchestrator currently offers OPERA_SSH_USER environment variable which is used by the Ansible executor when establishing the connection to a remote machine to tell which user someone wants to connect as. Similar to that there could be a variable called OPERA_SSH_KEY_FILE that would point to the file with a private ssh key that needs to be used when establishing a connection to the host.

Steps

As of now before deploying TOSCA templates opera creates an Ansible inventory in the background and sets the user within ansible_user entry if OPERA_SSH_USER was exported. Exactly this is done with the line: inventory["ansible_user"] = os.environ.get("OPERA_SSH_USER", "centos") so that user defaults to centos if this was not set to localhost before.

To implement the part for the ssh keys we would need to:

  1. use OPERA_SSH_KEY_FILE env var to point opera to the ssh key
  2. check the path to the ssh key file
  3. set the shh key in the opera's Ansible inventory with ansible_ssh_private_key_file entry

Current behaviour

Currently xOpera does not offer to choose ssh keys to connect but it expects that user managed that before by himself either with putting keys to the ~/.ssh folder or by creating ~/.ssh/config configuration file which offers matching IPs and ssh keys for connection.

Expected results

To be able to specify which ssh keys to use during the orchestration.

matejart commented 4 years ago

Thank you for the issue description, @anzoman. I feel that implementing your suggestion can be useful in some scenarios, where all the hosts to be managed will allow connections using the corresponding public SSH key.

Given that the environment will contain the path to the private key, I suggest that the env variable is either OPERA_SSH_PRIVATE_KEY_FILE or, if this is too long, OPERA_SSH_IDENTITY_FILE.

A few questions:

anzoman commented 4 years ago

@matejart thanks for your opinion OPERA_SSH_IDENTITY_FILE seems to be a good decision for the name. And to answer your questions:

anzoman commented 4 years ago

We are dunzo here! Since this was successfully implemented with #61 we can close this issue.