Re: [packer] Re: Packer build for fails with Bundler Bundler::SudoNotPermittedError

2019-08-31 Thread Rickard von Essen
Without analyzing what's going wrong I would take the path of least
resistance. Enabla password less (NOPASSWORD) for the user (ssh_username)
you are using and then run chef with sudo. That should work without any
problems.

And if you don't want passwordless sudo just remove it after chef have been
executed.

On Sat, Aug 31, 2019, 19:18 Rhythm Chopra  wrote:

> I have already tried execute command overload to the following.
>
> "execute_command": "echo password | sudo -S bash {{ .Script }}"
>
> But then my build fails with following logs.
>
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 opening new ssh session
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Starting remote scp
>> process:  scp -vt /tmp/packer-chef-solo
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Started SCP session,
>> beginning transfers...
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Copying input data into
>> temporary file so we can read the length
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 [DEBUG] scp: Uploading
>> solo.rb: perms=C0644 size=58
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 SCP session complete,
>> closing stdin pipe.
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Waiting for SSH session
>> to complete.
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 scp stderr (length 23):
>> Sink: C0644 58 solo.rb
>> 2019/08/31 20:17:06 ui: virtualbox-iso: Creating JSON attribute file
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 [INFO] 619 bytes written
>> for 'uploadData'
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 opening new ssh session
>> 2019/08/31 20:17:06 [INFO] 619 bytes written for 'uploadData'
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Starting remote scp
>> process:  scp -vt /tmp/packer-chef-solo
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Started SCP session,
>> beginning transfers...
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Copying input data into
>> temporary file so we can read the length
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 [DEBUG] scp: Uploading
>> node.json: perms=C0644 size=619
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 SCP session complete,
>> closing stdin pipe.
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Waiting for SSH session
>> to complete.
>> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 scp stderr (length 26):
>> Sink: C0644 619 node.json
>> 2019/08/31 20:17:06 [INFO] (telemetry) ending chef-solo
>> 2019/08/31 20:17:06 [INFO] (telemetry) found error: Error executing Chef:
>> template: root:1:31: executing "root" at <.Script>: can't evaluate field
>> Script in type *chefsolo.ExecuteTemplate
>>
>>
>
> Please suggest
>
> Thanks,
> Rhythm
>
>
> On Saturday, August 31, 2019 at 8:09:02 PM UTC+3, Rhythm Chopra wrote:
>>
>> Hi,
>> I'm struggling with a packer build for a long time now. So I'm trying to
>> build Ubuntu 1404 server image with Packer using chef provisioner.
>> Initially build was getting stuck at the following command after installing
>> chef successfully,
>>
>>> 2019/08/31 17:36:04 ui: ==> virtualbox-iso: Provisioning with chef-solo
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: Installing Chef...
>>> 2019/08/31 17:36:04 packer: 2019/08/31 17:36:04 opening new ssh session
>>> 2019/08/31 17:36:04 packer: 2019/08/31 17:36:04 starting remote command:
>>> curl -L https://omnitruck.chef.io/install.sh | { echo 'qwerty'; cat -;
>>> } | sudo -S bash -s -- -v 13.8.5
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: % Total% Received %
>>> Xferd  Average Speed   TimeTime Time  Current
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: Dload  Upload   Total
>>> SpentLeft  Speed
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: 0 00 00
>>> 0  0  0 --:--:-- --:--:-- --:--:-- 0[sudo] password for
>>> metasploitable3: no talloc stackframe at ../source3/param/loadparm.c:4864,
>>> leaking memory
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: 100 23103  100 23103
>>> 0 0   166k  0 --:--:-- --:--:-- --:--:--  167k
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: ubuntu 14.04 x86_64
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: Getting information for chef
>>> stable 13.8.5 for ubuntu...
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: downloading
>>> https://omnitruck.chef.io/stable/chef/metadata?v=13.8.5&p=ubuntu&pv=14.04&m=x86_64
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: to file
>>> /tmp/install.sh.1749/metadata.txt
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: trying wget...
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: sha1
>>> 1ecb70effcf557dbac0d0de528bbef6937f9c581
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: sha256
>>> ce0ff3baf39c8c13ed474104928e7e4568a4997a1d5797cae2b2ba3ee001e3a8
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: url
>>> https://packages.chef.io/files/stable/chef/13.8.5/ubuntu/14.04/chef_13.8.5-1_amd64.deb
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: version13.8.5
>>> 2019/08/31 17:36:04 ui: virtualbox-iso: downlo

[packer] Re: Packer build for fails with Bundler Bundler::SudoNotPermittedError

2019-08-31 Thread Rhythm Chopra
I have already tried execute command overload to the following.

"execute_command": "echo password | sudo -S bash {{ .Script }}"  

But then my build fails with following logs.

> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 opening new ssh session
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Starting remote scp 
> process:  scp -vt /tmp/packer-chef-solo
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Started SCP session, 
> beginning transfers...
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Copying input data into 
> temporary file so we can read the length
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 [DEBUG] scp: Uploading 
> solo.rb: perms=C0644 size=58
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 SCP session complete, 
> closing stdin pipe.
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Waiting for SSH session to 
> complete.
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 scp stderr (length 23): 
> Sink: C0644 58 solo.rb
> 2019/08/31 20:17:06 ui: virtualbox-iso: Creating JSON attribute file
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 [INFO] 619 bytes written 
> for 'uploadData'
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 opening new ssh session
> 2019/08/31 20:17:06 [INFO] 619 bytes written for 'uploadData'
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Starting remote scp 
> process:  scp -vt /tmp/packer-chef-solo
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Started SCP session, 
> beginning transfers...
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Copying input data into 
> temporary file so we can read the length
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 [DEBUG] scp: Uploading 
> node.json: perms=C0644 size=619
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 SCP session complete, 
> closing stdin pipe.
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 Waiting for SSH session to 
> complete.
> 2019/08/31 20:17:06 packer: 2019/08/31 20:17:06 scp stderr (length 26): 
> Sink: C0644 619 node.json
> 2019/08/31 20:17:06 [INFO] (telemetry) ending chef-solo
> 2019/08/31 20:17:06 [INFO] (telemetry) found error: Error executing Chef: 
> template: root:1:31: executing "root" at <.Script>: can't evaluate field 
> Script in type *chefsolo.ExecuteTemplate
>
>

Please suggest 

Thanks,
Rhythm


On Saturday, August 31, 2019 at 8:09:02 PM UTC+3, Rhythm Chopra wrote:
>
> Hi,
> I'm struggling with a packer build for a long time now. So I'm trying to 
> build Ubuntu 1404 server image with Packer using chef provisioner. 
> Initially build was getting stuck at the following command after installing 
> chef successfully,
>
>> 2019/08/31 17:36:04 ui: ==> virtualbox-iso: Provisioning with chef-solo
>> 2019/08/31 17:36:04 ui: virtualbox-iso: Installing Chef...
>> 2019/08/31 17:36:04 packer: 2019/08/31 17:36:04 opening new ssh session
>> 2019/08/31 17:36:04 packer: 2019/08/31 17:36:04 starting remote command: 
>> curl -L https://omnitruck.chef.io/install.sh | { echo 'qwerty'; cat -; } 
>> | sudo -S bash -s -- -v 13.8.5
>> 2019/08/31 17:36:04 ui: virtualbox-iso: % Total% Received % 
>> Xferd  Average Speed   TimeTime Time  Current
>> 2019/08/31 17:36:04 ui: virtualbox-iso: Dload  Upload   Total   
>> SpentLeft  Speed
>> 2019/08/31 17:36:04 ui: virtualbox-iso: 0 00 00 
>> 0  0  0 --:--:-- --:--:-- --:--:-- 0[sudo] password for 
>> metasploitable3: no talloc stackframe at ../source3/param/loadparm.c:4864, 
>> leaking memory
>> 2019/08/31 17:36:04 ui: virtualbox-iso: 100 23103  100 231030 
>> 0   166k  0 --:--:-- --:--:-- --:--:--  167k
>> 2019/08/31 17:36:04 ui: virtualbox-iso: ubuntu 14.04 x86_64
>> 2019/08/31 17:36:04 ui: virtualbox-iso: Getting information for chef 
>> stable 13.8.5 for ubuntu...
>> 2019/08/31 17:36:04 ui: virtualbox-iso: downloading 
>> https://omnitruck.chef.io/stable/chef/metadata?v=13.8.5&p=ubuntu&pv=14.04&m=x86_64
>> 2019/08/31 17:36:04 ui: virtualbox-iso: to file 
>> /tmp/install.sh.1749/metadata.txt
>> 2019/08/31 17:36:04 ui: virtualbox-iso: trying wget...
>> 2019/08/31 17:36:04 ui: virtualbox-iso: sha1
>> 1ecb70effcf557dbac0d0de528bbef6937f9c581
>> 2019/08/31 17:36:04 ui: virtualbox-iso: sha256
>> ce0ff3baf39c8c13ed474104928e7e4568a4997a1d5797cae2b2ba3ee001e3a8
>> 2019/08/31 17:36:04 ui: virtualbox-iso: url
>> https://packages.chef.io/files/stable/chef/13.8.5/ubuntu/14.04/chef_13.8.5-1_amd64.deb
>> 2019/08/31 17:36:04 ui: virtualbox-iso: version13.8.5
>> 2019/08/31 17:36:04 ui: virtualbox-iso: downloaded metadata file 
>> looks valid...
>> 2019/08/31 17:36:04 ui: virtualbox-iso: downloading 
>> https://packages.chef.io/files/stable/chef/13.8.5/ubuntu/14.04/chef_13.8.5-1_amd64.deb
>> 2019/08/31 17:36:04 ui: virtualbox-iso: to file 
>> /tmp/install.sh.1749/chef_13.8.5-1_amd64.deb
>> 2019/08/31 17:36:04 ui: virtualbox-iso: trying wget...
>> 2019/08/31 17:36:45 ui: virtualbox-iso: Com

[packer] Packer build for fails with Bundler Bundler::SudoNotPermittedError

2019-08-31 Thread Rhythm Chopra
Hi,
I'm struggling with a packer build for a long time now. So I'm trying to 
build Ubuntu 1404 server image with Packer using chef provisioner. 
Initially build was getting stuck at the following command after installing 
chef successfully,

> 2019/08/31 17:36:04 ui: ==> virtualbox-iso: Provisioning with chef-solo
> 2019/08/31 17:36:04 ui: virtualbox-iso: Installing Chef...
> 2019/08/31 17:36:04 packer: 2019/08/31 17:36:04 opening new ssh session
> 2019/08/31 17:36:04 packer: 2019/08/31 17:36:04 starting remote command: 
> curl -L https://omnitruck.chef.io/install.sh | { echo 'qwerty'; cat -; } | 
> sudo -S bash -s -- -v 13.8.5
> 2019/08/31 17:36:04 ui: virtualbox-iso: % Total% Received % Xferd  
> Average Speed   TimeTime Time  Current
> 2019/08/31 17:36:04 ui: virtualbox-iso: Dload  Upload   Total   
> SpentLeft  Speed
> 2019/08/31 17:36:04 ui: virtualbox-iso: 0 00 00 
> 0  0  0 --:--:-- --:--:-- --:--:-- 0[sudo] password for 
> metasploitable3: no talloc stackframe at ../source3/param/loadparm.c:4864, 
> leaking memory
> 2019/08/31 17:36:04 ui: virtualbox-iso: 100 23103  100 231030 
> 0   166k  0 --:--:-- --:--:-- --:--:--  167k
> 2019/08/31 17:36:04 ui: virtualbox-iso: ubuntu 14.04 x86_64
> 2019/08/31 17:36:04 ui: virtualbox-iso: Getting information for chef 
> stable 13.8.5 for ubuntu...
> 2019/08/31 17:36:04 ui: virtualbox-iso: downloading 
> https://omnitruck.chef.io/stable/chef/metadata?v=13.8.5&p=ubuntu&pv=14.04&m=x86_64
> 2019/08/31 17:36:04 ui: virtualbox-iso: to file 
> /tmp/install.sh.1749/metadata.txt
> 2019/08/31 17:36:04 ui: virtualbox-iso: trying wget...
> 2019/08/31 17:36:04 ui: virtualbox-iso: sha1
> 1ecb70effcf557dbac0d0de528bbef6937f9c581
> 2019/08/31 17:36:04 ui: virtualbox-iso: sha256
> ce0ff3baf39c8c13ed474104928e7e4568a4997a1d5797cae2b2ba3ee001e3a8
> 2019/08/31 17:36:04 ui: virtualbox-iso: url
> https://packages.chef.io/files/stable/chef/13.8.5/ubuntu/14.04/chef_13.8.5-1_amd64.deb
> 2019/08/31 17:36:04 ui: virtualbox-iso: version13.8.5
> 2019/08/31 17:36:04 ui: virtualbox-iso: downloaded metadata file looks 
> valid...
> 2019/08/31 17:36:04 ui: virtualbox-iso: downloading 
> https://packages.chef.io/files/stable/chef/13.8.5/ubuntu/14.04/chef_13.8.5-1_amd64.deb
> 2019/08/31 17:36:04 ui: virtualbox-iso: to file 
> /tmp/install.sh.1749/chef_13.8.5-1_amd64.deb
> 2019/08/31 17:36:04 ui: virtualbox-iso: trying wget...
> 2019/08/31 17:36:45 ui: virtualbox-iso: Comparing checksum with 
> sha256sum...
> 2019/08/31 17:36:46 ui: virtualbox-iso: Installing chef 13.8.5
> 2019/08/31 17:36:46 ui: virtualbox-iso: installing with dpkg...
> 2019/08/31 17:36:46 ui: virtualbox-iso: Selecting previously 
> unselected package chef.
> 2019/08/31 17:36:46 ui: virtualbox-iso: (Reading database ... 68348 
> files and directories currently installed.)
> 2019/08/31 17:36:46 ui: virtualbox-iso: Preparing to unpack 
> .../chef_13.8.5-1_amd64.deb ...
> 2019/08/31 17:36:46 ui: virtualbox-iso: Unpacking chef (13.8.5-1) ...
> 2019/08/31 17:36:52 ui: virtualbox-iso: Setting up chef (13.8.5-1) ...
> 2019/08/31 17:36:52 ui: virtualbox-iso: Thank you for installing Chef!
> 2019/08/31 17:36:52 packer: 2019/08/31 17:36:52 [INFO] RPC endpoint: 
> Communicator ended with: 0
> 2019/08/31 17:36:52 [INFO] 0 bytes written for 'stderr'
> 2019/08/31 17:36:52 [INFO] 2006 bytes written for 'stdout'
> 2019/08/31 17:36:52 [INFO] RPC client: Communicator ended with: 0
> 2019/08/31 17:36:52 [INFO] RPC endpoint: Communicator ended with: 0
> 2019/08/31 17:36:52 packer: 2019/08/31 17:36:52 [INFO] 2006 bytes written 
> for 'stdout'
> 2019/08/31 17:36:52 packer: 2019/08/31 17:36:52 [INFO] 0 bytes written for 
> 'stderr'
> 2019/08/31 17:36:52 packer: 2019/08/31 17:36:52 [INFO] RPC client: 
> Communicator ended with: 0
> 2019/08/31 17:36:52 ui: virtualbox-iso: Creating directory: 
> /tmp/packer-chef-solo
> 2019/08/31 17:36:52 packer: 2019/08/31 17:36:52 opening new ssh session
> 2019/08/31 17:36:52 packer: 2019/08/31 17:36:52 starting remote command: 
> mkdir -p '/tmp/packer-chef-solo'
>
>
Looks like it was waiting for password because `sudo` was being used. So I 
added the flag 
prevent_sudo= true

Now, the above steps completed properly, but later my build fails at 

> 2019/08/31 17:36:53 packer: 2019/08/31 17:36:53 opening new ssh session
> 2019/08/31 17:36:53 [INFO] 58 bytes written for 'uploadData'
> 2019/08/31 17:36:53 packer: 2019/08/31 17:36:53 Starting remote scp 
> process:  scp -vt /tmp/packer-chef-solo
> 2019/08/31 17:36:53 packer: 2019/08/31 17:36:53 Started SCP session, 
> beginning transfers...
> 2019/08/31 17:36:53 packer: 2019/08/31 17:36:53 Copying input data into 
> temporary file so we can read the length
> 2019/08/31 17:36:53 packer: 2019/08/31 17:36:53 [DEBUG] scp: Uploading 
> solo.rb: perms=C0644 size=58
> 2019/08/31 17:36:53 packer