Adding sudoers.d/<file> to image

16 views
Skip to first unread message

Kevin Milner

unread,
Feb 9, 2018, 3:23:39 PM2/9/18
to Packer
Hello, I'm trying to add a file to /etc/sudoers.d/ in order to allow one specific user (named 'config') to run one specific program without entering a sudo password.
First of all, here is my privilege file,  'files/hydra-common/sudoers/config_user'

# add config script to sudoers so the user only needs to enter the password on login
config ALL
=(ALL) NOPASSWD:/home/config/config_startup.sh

I upload the file in my template:
 
 
{
    "type": "file",
   
"source": "files/common/",
   
"destination": "/tmp/hydra-common"
},

then later, in a script, I call:
echo "Moving Sudoers files"
chown
-R 0 /tmp/hydra-common/sudoers/*
chmod 440 /tmp/hydra-common/sudoers/*
mv /tmp/hydra-common/sudoers/* /etc/sudoers.d/

I don't get any errors at this point, but then in the next provision shell step, I get the following error
    vsphere: >>> /etc/sudoers.d/config_users: syntax error near line 2 <<<
    vsphere
: sudo: parse error in  near line 2
    vsphere
: sudo: no valid sudoers sources found, quitting


No, if I comment out the effective line in the privilege file, I obviously don't get the error, but just as obvious is that I don't get the sudo permission for config. if I use visudo to edit the file (from root), and uncomment the line, visudo does not give me any errors, so I'm guessing the syntax is correct.
I'm thinking it might be because when the script does it, its not doing it through visudo which is confusing linux? At any rate, does anyone have any idea how to fix this?

I'm using Ubuntu 16.04 and Vcenter (with the vsphere plugin found here: https://github.com/jetbrains-infra/packer-builder-vsphere)

Rickard von Essen

unread,
Feb 9, 2018, 3:45:57 PM2/9/18
to packe...@googlegroups.com
Run with -on-error=ask go into the machine and troubleshoot. 

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/08d1bbef-45ad-4f15-bc86-e822b3275b15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alvaro Miranda Aguilera

unread,
Feb 9, 2018, 5:32:23 PM2/9/18
to packe...@googlegroups.com
are you on windows? if yes, run dos2unix in the files




For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Kevin Milner

unread,
Feb 10, 2018, 9:39:02 AM2/10/18
to Packer

No, both my workstation and the target are running Ubuntu flavored Linux.

Rickard von Essen

unread,
Feb 10, 2018, 11:02:01 AM2/10/18
to packe...@googlegroups.com
If you share your complete template and scripts it's simpler to spot what's wrong. I think everything so far looks correct.

--
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+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages