Passwordless sudo... how is it achieved?

36 views
Skip to first unread message

John Patrick

unread,
Sep 27, 2019, 2:13:48 PM9/27/19
to Vagrant
I'm trying to use packer to boot a vagrant box, execute some ansible playbooks/tasks and then export the vagrant box.
I raised an issue/question with packer https://github.com/hashicorp/packer/issues/8148 and was told to configure the password for ansible to use. But vagrant achieves passwordless sudo without extra configuration with the exact same box.

My question is how is passwordless sudo achieved? Are are you aware what extra configure i need to do for packer, so it achieve the same seamless integration that vagrant does, when i get packer calling vagrant executing ansible?

Daniel Gil Jara

unread,
Sep 27, 2019, 2:30:12 PM9/27/19
to vagra...@googlegroups.com
Passwordless configs? We're crazy? I've used packer for generate Gentoo images, it is very good software. For passwordless sudo use the google.

Atentamente,
Daniel Gil


--
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/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/d7bf6e0f-c157-4de0-b78e-58898c01fb8d%40googlegroups.com.

John Patrick

unread,
Sep 27, 2019, 2:43:07 PM9/27/19
to vagra...@googlegroups.com
just to confirm i can configure passwordless sudo, but google didn’t have any useful links for

“packer vagrant passwordless sudo not working”

i’m trying to understand the low level detail of vagrant and when i do ‘vagrant up’ and have an ansible playbook, how is vagrant booting the box and installing ansible automatically, then executing ansible playbooks. so i can then debug packer and see which steps are differently. as packer isn’t automatically installing ansible and sudo doesn’t work.

but when i boot the box in vagrant, passwordless sudo works as expected.

i’m trying with ubuntu boxes.

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/eQe8kwWqnno/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAG9%3Df1owEEB8Qqpt7iKZ8zdWZpQy_gMbFkv2PPorzzPnp3XT-A%40mail.gmail.com.

John Patrick

unread,
Sep 27, 2019, 2:44:29 PM9/27/19
to vagra...@googlegroups.com
daniel can you confirm how your building the gentoo images... from iso? exciting vagrant box? other?

Sent from my iPhone

Dennis Chang

unread,
Sep 27, 2019, 2:58:22 PM9/27/19
to Vagrant
Hi John,

[vagrant@centos-01 ~]$ sudo cat /etc/sudoers.d/vagrant
vagrant        ALL=(ALL)       NOPASSWD: ALL
[vagrant@centos-01 ~]$

John Patrick

unread,
Sep 27, 2019, 3:36:58 PM9/27/19
to vagra...@googlegroups.com
correct dennis that is how you do passwordless sudo...

just to confirm before someone else replies to thread or emails me
directly, telling me to google sudoers or passwordless, this is my
current configuration for vagrant and everything works as expected.

host$ vagrant init ubuntu/bionic64
host$ vagrant ssh
box$ sudo cat /etc/sudoers.d/vagrant
vagrant ALL=(ALL) NOPASSWD:ALL
box $
EVERYTHING WORKS AS EXPECTED

my issue is when packer, calls vagrant which executes ansible. I get
"sudo: a password is required"

so what I'm trying to understand is the different between how vagrant
and packer work. why vagrant/ansible works and is passwordless but
packer/vagrant/ansible is asking for a password when using the same
source vagrant box and same ansible playbook.

John
> --
> 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/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/eQe8kwWqnno/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/d3b657bd-b295-4a37-b32f-95613afa58cc%40googlegroups.com.

Dennis Chang

unread,
Sep 27, 2019, 3:50:37 PM9/27/19
to Vagrant
Hi John,

From what I know about packer, packer builds a VM in 3 phases,

builders
provisions
post-processors


In the builders phase, packer boots from an ISO image, and runs build commands.
In this phase, you add vagrant user and add the /etc/sudoers.d/vagrant file.

Packer stops the VM and then starts the VM in the provisioners phase.
Here is where you probably want to run your ansible commands.

Given that this is a group about vagrant (and not packer) I would suggest you
include the command you are using to run packer (which runs vagrant) and
provide the output. Perhaps most of us haven't used packer and vagrant together before.

Dennis

Alvaro Miranda Aguilera

unread,
Sep 29, 2019, 6:08:56 PM9/29/19
to vagra...@googlegroups.com
if you are using packer with vagrant provider, is expected the box will be ssh and ready to use

usually will have a vagrant user with the vagrant known ssh

so vagrant can ssh.

on first boot, vagrant will insert a new ssh cred.

you can see what ssh will be used with 

vagrant ssh-config



you could avoid change of the ssh key with config.ssh.insert_key = false



you can read more here

alvaro.

--
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/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/d7bf6e0f-c157-4de0-b78e-58898c01fb8d%40googlegroups.com.


--
Alvaro

Reply all
Reply to author
Forward
Message has been deleted
0 new messages