Need to implement stackstorm actions

Hi,

I am new to stackstorm and Kindly help me on the below requirement.

Manual Process:
step1: We are logging into a server using user credentials
step2: switching to docker user using: sudo su - docker (it is not asking password)
Step3: Now executing the commands:
systemctl start docker
systemctl stop docker
systemctl restart docker

I know we can use remote shell command runner type for the action but how to switch to docker user from user and run above commands.

@Narendra4st2

like remote you can use the remote_sudo action from the core pack. remote_sudo will run the command as sudo. I’m guessing something like this should work for you.

st2 run core.remote_sudo cmd="su - docker; <commands/script that you might want to execute>" username="<remote-host-ssh-username>"  password="<remote-host-ssh-password>" hosts="localhost/remote-host"

If passwordless sudo is not enabled then you can also pass the sudo_password to the action. Hope this helps.

2 Likes

@Sheshagiri Thank you it is working.

2 Likes