Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cloud/Amazon SSM Send-Command Module #54931

Open
wants to merge 11 commits into
base: devel
from

Conversation

Projects
None yet
4 participants
@sosheskaz
Copy link
Contributor

commented Apr 5, 2019

SUMMARY

This is an extension of PR #19868, addressing some of the feedback that was left on the PR but not addressed by the original author.

Usage of some best-practices for boto3 programming were also included, including usage of AWSRetry.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

ssm_send_command

ADDITIONAL INFORMATION

AWS SSM is an AWS system that allows one to manage systems in AWS or on-premise using an Amazon agent and pre-made "documents", which define the commands which can be sent to an instance.

For example, the following runs the AWS-UpdateSSMAgent command document on the instance i-0123456789abcde012:

$ ansible localhost -m "ssm_send_command" -a "name=AWS-UpdateSSMAgent instance_ids=i-0123456789abcde012"
localhost | CHANGED => {
    "changed": true,
    "result": {
        "output": "Updating amazon-ssm-agent from 2.3.539.0 to latest\nSuccessfully downloaded https://s3.us-west-2.amazonaws.com/amazon-ssm-us-west-2/ssm-agent-manifest.json\namazon-ssm-agent 2.3.539.0 has already been installed, update skipped\n",
        "status": "Success"
    }
}
@ansibot

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

@sosheskaz this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

@sosheskaz This PR contains @ mentions in at least one commit message. Those mentions can cause cascading notifications through GitHub and need to be removed. Please squash or amend your commits to remove the mentions.

click here for bot help

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

The test ansible-test sanity --test pylint [explain] failed with 5 errors:

lib/ansible/modules/cloud/amazon/ssm_send_command.py:67:0: anomalous-backslash-in-string Anomalous backslash in string: '\c'. String constant might be missing an r prefix.
lib/ansible/modules/cloud/amazon/ssm_send_command.py:67:0: anomalous-backslash-in-string Anomalous backslash in string: '\g'. String constant might be missing an r prefix.
lib/ansible/modules/cloud/amazon/ssm_send_command.py:67:0: anomalous-backslash-in-string Anomalous backslash in string: '\s'. String constant might be missing an r prefix.
lib/ansible/modules/cloud/amazon/ssm_send_command.py:67:0: anomalous-backslash-in-string Anomalous backslash in string: '\s'. String constant might be missing an r prefix.
lib/ansible/modules/cloud/amazon/ssm_send_command.py:67:0: anomalous-backslash-in-string Anomalous backslash in string: '\s'. String constant might be missing an r prefix.

The test ansible-test sanity --test ansible-doc --python 3.8 [explain] failed with the error:

Output on stderr from ansible-doc is considered an error.

Command "ansible-doc -t module ssm_send_command" returned exit status 0.
>>> Standard Error
<unknown>:67: SyntaxWarning: invalid escape sequence \s

The test ansible-test sanity --test import --python 3.8 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ssm_send_command.py:67:0: SyntaxWarning: invalid escape sequence \s

The test ansible-test sanity --test pep8 [explain] failed with 5 errors:

lib/ansible/modules/cloud/amazon/ssm_send_command.py:76:14: W605 invalid escape sequence '\s'
lib/ansible/modules/cloud/amazon/ssm_send_command.py:76:22: W605 invalid escape sequence '\g'
lib/ansible/modules/cloud/amazon/ssm_send_command.py:77:14: W605 invalid escape sequence '\s'
lib/ansible/modules/cloud/amazon/ssm_send_command.py:77:22: W605 invalid escape sequence '\c'
lib/ansible/modules/cloud/amazon/ssm_send_command.py:79:14: W605 invalid escape sequence '\s'

The test ansible-test sanity --test validate-modules [explain] failed with 12 errors:

lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E305 DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got 'Joe Wozniak <woznij@amazon.com>'
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E307 version_added should be '2.8'. Currently '2.3'
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E314 No ANSIBLE_METADATA provided
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E319 RETURN.status.returned: required key not provided @ data['status']['returned']. Got None
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E322 Argument 'aws_region' is listed in the argument_spec, but not documented in the module documentation
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E322 Argument 'ec2_region' is listed in the argument_spec, but not documented in the module documentation
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E322 Argument 'region' is listed in the argument_spec, but not documented in the module documentation
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E324 Argument 'comment' in argument_spec defines default as (None) but documentation defines default as ('NONE')
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E324 Argument 'instance_ids' in argument_spec defines default as (None) but documentation defines default as (['NONE'])
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E324 Argument 'name' in argument_spec defines default as (None) but documentation defines default as ('NONE')
lib/ansible/modules/cloud/amazon/ssm_send_command.py:0:0: E326 Argument 'wait' in argument_spec defines choices as ([False, True, True, False, False, False, True, False, True, True, True, False, True, False]) but documentation defines choices as ([])
lib/ansible/modules/cloud/amazon/ssm_send_command.py:76:15: E311 EXAMPLES is not valid YAML

The test ansible-test sanity --test yamllint [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ssm_send_command.py:76:15: error EXAMPLES: syntax error: found unknown escape character 's'

click here for bot help

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

@sosheskaz, just so you are aware we have a dedicated Working Group for aws.
You can find other people interested in this in #ansible-aws on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

woznij and others added some commits Oct 26, 2016

Added cloud/Amazon module for SSM
This module allows you to interface with Amazon Simple Systems Manager (SSM) to manage the configuration of your Amazon EC2 instances.  Specifically this module allows you to use the Run Command functionality to run system commands against your hosts. E.g. you can run PowerShell commands against Windows hosts or bash commands against a Linux host. The specific advantage is that you do not need to log into those hosts as the SSM service takes care of the execution. For more information see http://docs.aws.amazon.com/ssm/latest/APIReference/Welcome.html
Updated imports section, fixed regression of version_added string <sq…
…uashed commit to remove user reference> (+1 squashed commit)

Squashed commits:
[119c0bc933] Made updates as per willthames suggestions

@sosheskaz sosheskaz force-pushed the sosheskaz:devel branch from bd0a756 to 6d9cccb Apr 12, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Apr 12, 2019

@BobBoldin @Constantin007 @Constantin07 @Deepakkothandan @Etherdaemon @Java1Guy @Madhura-CSI @MichaelBaydoun @Sodki @Zeekin @adq @akazakov @alachaum @amir343 @anryko @bekelchik @brandond @captainkerk @chenl87 @defunctio @dennisconrad @dkhenry @fiunchinho @fivethreeo @flowerysong @garethr @gobins @gunzy83 @gurumaia @hsingh @hyperized @iiibrad @infectsoldier @j-carl @jarv @Java1Guy @jimbydamonk @jmenga @joelthompson @jonhadfield @jonmer85 @joshsouza @jsdalton @jsmartin @kaczynskid @leedm777 @linuxdynasty @loia @lwade @michaeljs1990 @minichate @mjschultz @mmochan @nand0p @naslanidis @nathanwebsterdotme @nerzhul @nickball @orthanc @ozbillwang @piontas @pjodouin @prasadkatti @psykotox @ptux @pwnall @raags @rafaeldriutti @rickmendes @roadmapper @rrey @ryansb @ryansydnor @scicoin-project @scottanderson42 @sdubrul @shepdelacreme @silviud @slapula @steynovich @tastychutney @tgerla @timmahoney @tomislacker @tsiganenok @viper233 @whiter @willricardo @wilvk @wimnat @yaakov-github @zacblazic @zbal @zimbatm

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@ansibot ansibot removed the needs_revision label Apr 12, 2019



def main():
argument_spec = ec2_argument_spec()

This comment has been minimized.

Copy link
@flowerysong

flowerysong Apr 12, 2019

Contributor

This is unnecessary, by default AnsibleAWSModule automatically merges the spec you pass it with ec2_argument_spec().

instance_ids = module.params.get('instance_ids')
parameters = module.params.get('parameters')

if not HAS_BOTO3:

This comment has been minimized.

Copy link
@flowerysong

flowerysong Apr 12, 2019

Contributor

This is unnecessary, AnsibleAWSModule handles it.

module.fail_json(
msg="Must provide SSM document name and at least one instance id.")

region, ec2_url, aws_connect_kwargs = get_aws_connection_info(

This comment has been minimized.

Copy link
@flowerysong

flowerysong Apr 12, 2019

Contributor

This whole connection block can be replaced with conn = module.client('ssm')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.