ansible-community / molecule-plugins

Collection on molecule plugins
MIT License
101 stars 67 forks source link

Support for AWS SSM connection #232

Open nandac opened 5 months ago

nandac commented 5 months ago

Dear Folks,

I am using EC2 driver and want to use AWS SSM to connect to the instance as SSH is closed off on the images we use at our organization.

I believe the relevant code is here: https://github.com/ansible-community/molecule-plugins/blob/5ebdfc60e457d5303e45fb237840e6592b98715f/src/molecule_plugins/ec2/driver.py#L221

which only supports SSH and WinRM.

I can add another if statement here like this in the code but not sure this is the right approach

if conn_opts.get("ansible_connection") == "community.aws.aws_ssm":
    conn_opts["connection"] = "community.aws.aws_ssm"
    conn_opts["user"] = "ssm-user"

Secondly, the ansible_connection_options function is called in login_cmd_template function where it looks like a command to be run in a terminal is returned.

Does this mean that I should return an AWS CLI SSM command from this function to enable login. This poses some issues because a profile and region may need to be sent in to enable access through SSM.

I hope someone can guide me in this regard and I am happy to contribute this code once I have got it working.