skip to Main Content

I have an SSM environment in AWS, and I have client machines that are joining without any issues. I am able to remote connect to the terminal and run commands, everything works up to this point.

Now I am trying to run terminal commands on the devices en masse. So I would like to, for example, run this:

echo 192.168.1.1 MyServer.domain.com >> /etc/hosts
apt install realmd
echo MyPassword | realm join -v --user=MyUsername domain.com
sudo reboot

So to package this script up in a tidy little unit of some kind that I can push out to devices as I require. But I can’t seem to find any way that this can be done.

2

Answers


  1. maybe I’m misunderstanding the question, but SSM has a concept of "Documents" where you can store your scripts and supports a "Run Command" which can be used to run the document against your "fleet" of machines.

    It even supports rate controls and more advanced feature.

    Link for the documentation can be found here: https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-multiple.html

    Login or Signup to reply.
  2. you can try this script :

    #!/bin/bash
    
    instances=(i-instance-1 i-instance-2)
    for instance in "${instances[@]}"; do
        aws ssm send-command --document-name "AWS-RunShellScript"
                             --targets "Key=instanceIds,Values=$instance"
                             --parameters 'commands=["echo 192.168.1.1 MyServer.domain.com >> /etc/hosts","apt install realmd","echo MyPassword | realm join -v --user=MyUsername domain.com","reboot"]'
    done
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search