Re: [packer] sudo script with packer

5,680 views
Skip to first unread message
Message has been deleted

Alvaro Miranda Aguilera

unread,
Feb 19, 2016, 8:13:47 AM2/19/16
to packe...@googlegroups.com
Hello,


What command you should type on the command line to get this working?

I am not sure if you are telling the packer template to run as root, abc or other user, so the line you would type will help to understand better.

Thanks
Alvaro.

On Sat, Feb 20, 2016 at 1:11 AM, <sidhur...@gmail.com> wrote:
Hi,

I would like to do following :-

login with ec2-user .. and sudo to some other user and execute deployment script. 

So, packer working fine.. AMI creation is ok.. But while executing below script it gives me an error that it should run with "abc" user and not root user.

I have added ec2-user in sudoers files :-

ec2-user ALL=(ALL) <script path>


"provisioners": [

   {
        "type": "shell",
        "execute_command": "echo '' | sudo -S sh '{{ .Path }}'",
        "environment_vars": [
                                "SUDO_USER={{user `dep_user`}}"
                        ],

        "scripts": [
                                "/eserver1/share/deployment_kit/deploy.sh"
                ]

   }

In variables :- 

"dep_user": "abc",

Can you please tell where it's wrong ?

Regards,
Sudh

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/7bf40aba-5395-476d-accd-da774b1d7bd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sidhur...@gmail.com

unread,
Feb 19, 2016, 8:34:49 AM2/19/16
to Packer
Hi Alvaro,

Thx for your reply..

So, login with ec2-user and then following command :-

sudo su - abc -c "<script-name>".. 

Regards,
Sudhir

Chris Bednarski

unread,
Feb 19, 2016, 2:53:28 PM2/19/16
to Packer
You can also use sudo -u to specify the user e.g:

sudo -u abc [command]

Alvaro Miranda Aguilera

unread,
Feb 19, 2016, 6:31:53 PM2/19/16
to packe...@googlegroups.com

On Sat, Feb 20, 2016 at 2:34 AM, <sidhur...@gmail.com> wrote:
sudo su - abc -c "<script-name>".. 

Hello,

Ah, well, 2 options here.

You are running as root that command

arguments="su - abc -c <script-name>"

so in your packer script you can just do


"provisioners": [

   {
        "type": "shell",
        "execute_command": "echo '' | sudo -S su - abc -c '{{ .Path }}'",
        "scripts": [
                                "/eserver1/share/deployment_kit/deploy.sh"
                ]

   }

^ this should run since is run as root and root should have access too all commands


As Chris said, the command should be
sudo -u abc "<script-name>"

so in packer:

"provisioners": [

   {
        "type": "shell",
        "execute_command": "echo '' | sudo -S -u abc '{{ .Path }}'",
        "scripts": [
                                "/eserver1/share/deployment_kit/deploy.sh"
                ]

   }

^ problem with that is the path won't be the same, the path of the script will be changed to `/tmp/<something>` so it will fail


if user that you use to login have access to run any command, as any user then should work.

Hope this helps.
Alvaro.



Reply all
Reply to author
Forward
0 new messages