Re: [packer] Trouble with sshd_config with packer + virtualbox + vagrant

2019-08-14 Thread Stephen Schlie
I had thought the same but cloud-init does not seem to be installed on the 
18.04.3 server image 
(http://cdimage.ubuntu.com/ubuntu/releases/bionic/release/ubuntu-18.04.3-server-amd64.iso)
 
so I'm reasonably confident that isn't it, unless cloud-init is sneakily on 
there somehow but not showing? I don't see it's dirs in `/etc/cloud` or in 
`/var/lib/cloud` nor does it show in `apt list --installed`.

On Wednesday, August 14, 2019 at 10:55:47 AM UTC-7, Rickard von Essen wrote:
>
> One guess would be that cloud-init might do this. 
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/bcf789a6-3090-4e23-8c45-b0a4ef8889a9%40googlegroups.com.


Re: [packer] Trouble with sshd_config with packer + virtualbox + vagrant

2019-08-14 Thread Rickard von Essen
One guess would be that cloud-init might do this.

On Wed, Aug 14, 2019, 19:19 Stephen Schlie  wrote:

> Hi Folks,
>
> I've run into an issue recently with packer where my output vagrant box
> has password based ssh disabled by default, even when I explicitly enable
> it in the last provisioner step. I'll include the template json below but
> in short we build an ubuntu 18.04.3 image with the virtualbox-iso builder,
> run a couple of scripts to setup things, and output the box.
>
> This was working until recently, I went and updated our setup to start
> building amis too, and the vagrant VMs stopped working. I tried rolling
> most of it back to see if it helped but I am still seeing this issue.
>
> template:
>
>   "_comment": "This file managed by salt. Local changes will be
> overwritten.",
>   "builders": [
> {
>   "vm_name": "{{user `vmname`}}",
>   "type": "virtualbox-iso",
>   "headless": true,
>   "vrdp_bind_address": "0.0.0.0",
>   "guest_os_type": "Ubuntu_64",
>   "iso_url": "http://{{user `webserver`}}/{{user `os_file`}}.iso",
>   "iso_checksum_url": "{{user `iso_checksum`}}",
>   "iso_checksum_type": "file",
>   "ssh_username": "packer",
>   "ssh_password": "packer",
>   "ssh_wait_timeout": "15m",
>   "shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
>   "disk_size": "3",
>   "hard_drive_interface": "sata",
>   "vboxmanage": [
> [
>   "modifyvm",
>   "{{.Name}}",
>   "--boot1",
>   "dvd"
> ],
> [
>   "modifyvm",
>   "{{.Name}}",
>   "--boot2",
>   "disk"
> ],
> [
>   "modifyvm",
>   "{{.Name}}",
>   "--nictype1",
>   "virtio"
> ],
> [
>   "modifyvm",
>   "{{.Name}}",
>   "--memory",
>   "2048"
> ],
> [
>   "modifyvm",
>   "{{.Name}}",
>   "--cpus",
>   "4"
> ],
> [
>   "modifyvm",
>   "{{.Name}}",
>   "--audio",
>   "none"
> ],
> [
>   "modifyvm",
>   "{{.Name}}",
>   "--usb",
>   "off"
> ]
>   ],
>   "boot_command": [
> "",
> "/install/vmlinuz noapic ",
> "preseed/url=http://{{user `webserver`}}/{{user `os_file`}}.cfg ",
> "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
> "hostname={{user `vmname`}} ",
> "fb=false debconf/frontend=noninteractive ",
> "keyboard-configuration/modelcode=SKIP
> keyboard-configuration/layout=USA ",
> "keyboard-configuration/variant=USA
> console-setup/ask_detect=false ",
> "DEBCONF=debug ",
> "initrd=/install/initrd.gz -- "
>   ],
>   "output_directory": "vbox/"
> },
> {
>   "type": "amazon-ebs",
>   "access_key": "{{ user `access_key` }}",
>   "secret_key": "{{ user `secret_key` }}",
>   "ami_users": [
> "",
> ""
>   ],
>   "region": "us-east-1",
>   "source_ami_filter": {
> "filters": {
>   "name":
> "ubuntu/images/hvm-ssd/*ubuntu-bionic-18.04-amd64-server-*",
>   "root-device-type": "ebs"
> },
> "owners": ["099720109477"],
> "most_recent": true
>   },
>   "vpc_id": "vpc-04ee3040de35bc755",
>   "subnet_id": "subnet-05b0e1ad8679eb394",
>   "instance_type": "t3.micro",
>   "ssh_username": "ubuntu",
>   "ami_name": "{{user `vmname`}}-{{user `salt_environment`}}-{{ user
> `commit` }}",
>   "spot_price": "0.0104",
>   "run_tags": {
> "application": "packer"
>   }
> }
>   ],
>   "provisioners": [
> {
>   "type": "file",
>   "source": "upload/",
>   "destination": "/tmp"
> },
> {
>   "type": "shell",
>   "inline": [
> "/usr/bin/cloud-init status --wait"
>   ],
>   "only": ["amazon-ebs"]
> },
> {
>   "type": "shell",
>   "scripts": [
> "/etc/vmimage/init.sh"
>   ],
>   "environment_vars": [
> "SALT_ENVIRONMENT={{user `salt_environment`}}",
> "SALT_VERSION={{user `salt_version`}}",
> "SLS_STATES={{user `sls_states`}}"
>   ]
> },
> {
>   "type": "shell",
>   "inline": [
> "sudo mount /home/packer/VBoxGuestAdditions.iso /mnt",
> "sudo sh /mnt/VBoxLinuxAdditions.run || true",
> "sudo umount /mnt",
> "sudo dmidecode -s system-product-name > /home/packer/vmtype"
>   ],
>   "only": ["virtualbox-iso"]
> },
> {
>   "type": "shell",
>   "inline": [
> "sudo sed -i 's/^PasswordAuthentication no/PasswordAuthentication
> yes/' /etc/ssh/sshd_config",
> "sudo cat /etc/ssh/sshd_config"
>   ],
>   "only": ["virtualbox-iso"]
>  }
>   ],
>   "post-processors": [
> {
>   "type": "vagrant",
>   "output": 

[packer] Trouble with sshd_config with packer + virtualbox + vagrant

2019-08-14 Thread Stephen Schlie
Hi Folks,

I've run into an issue recently with packer where my output vagrant box has 
password based ssh disabled by default, even when I explicitly enable it in 
the last provisioner step. I'll include the template json below but in 
short we build an ubuntu 18.04.3 image with the virtualbox-iso builder, run 
a couple of scripts to setup things, and output the box.

This was working until recently, I went and updated our setup to start 
building amis too, and the vagrant VMs stopped working. I tried rolling 
most of it back to see if it helped but I am still seeing this issue.

template:

  "_comment": "This file managed by salt. Local changes will be 
overwritten.",
  "builders": [
{
  "vm_name": "{{user `vmname`}}",
  "type": "virtualbox-iso",
  "headless": true,
  "vrdp_bind_address": "0.0.0.0",
  "guest_os_type": "Ubuntu_64",
  "iso_url": "http://{{user `webserver`}}/{{user `os_file`}}.iso",
  "iso_checksum_url": "{{user `iso_checksum`}}",
  "iso_checksum_type": "file",
  "ssh_username": "packer",
  "ssh_password": "packer",
  "ssh_wait_timeout": "15m",
  "shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
  "disk_size": "3",
  "hard_drive_interface": "sata",
  "vboxmanage": [
[
  "modifyvm",
  "{{.Name}}",
  "--boot1",
  "dvd"
],
[
  "modifyvm",
  "{{.Name}}",
  "--boot2",
  "disk"
],
[
  "modifyvm",
  "{{.Name}}",
  "--nictype1",
  "virtio"
],
[
  "modifyvm",
  "{{.Name}}",
  "--memory",
  "2048"
],
[
  "modifyvm",
  "{{.Name}}",
  "--cpus",
  "4"
],
[
  "modifyvm",
  "{{.Name}}",
  "--audio",
  "none"
],
[
  "modifyvm",
  "{{.Name}}",
  "--usb",
  "off"
]
  ],
  "boot_command": [
"",
"/install/vmlinuz noapic ",
"preseed/url=http://{{user `webserver`}}/{{user `os_file`}}.cfg ",
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
"hostname={{user `vmname`}} ",
"fb=false debconf/frontend=noninteractive ",
"keyboard-configuration/modelcode=SKIP 
keyboard-configuration/layout=USA ",
"keyboard-configuration/variant=USA console-setup/ask_detect=false "
,
"DEBCONF=debug ",
"initrd=/install/initrd.gz -- "
  ],
  "output_directory": "vbox/"
},
{
  "type": "amazon-ebs",
  "access_key": "{{ user `access_key` }}",
  "secret_key": "{{ user `secret_key` }}",
  "ami_users": [
"",
""
  ],
  "region": "us-east-1",
  "source_ami_filter": {
"filters": {
  "name": 
"ubuntu/images/hvm-ssd/*ubuntu-bionic-18.04-amd64-server-*",
  "root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
  },
  "vpc_id": "vpc-04ee3040de35bc755",
  "subnet_id": "subnet-05b0e1ad8679eb394",
  "instance_type": "t3.micro",
  "ssh_username": "ubuntu",
  "ami_name": "{{user `vmname`}}-{{user `salt_environment`}}-{{ user 
`commit` }}",
  "spot_price": "0.0104",
  "run_tags": {
"application": "packer"
  }
}
  ],
  "provisioners": [
{
  "type": "file",
  "source": "upload/",
  "destination": "/tmp"
},
{
  "type": "shell",
  "inline": [
"/usr/bin/cloud-init status --wait"
  ],
  "only": ["amazon-ebs"]
},
{
  "type": "shell",
  "scripts": [
"/etc/vmimage/init.sh"
  ],
  "environment_vars": [
"SALT_ENVIRONMENT={{user `salt_environment`}}",
"SALT_VERSION={{user `salt_version`}}",
"SLS_STATES={{user `sls_states`}}"
  ]
},
{
  "type": "shell",
  "inline": [
"sudo mount /home/packer/VBoxGuestAdditions.iso /mnt",
"sudo sh /mnt/VBoxLinuxAdditions.run || true",
"sudo umount /mnt",
"sudo dmidecode -s system-product-name > /home/packer/vmtype"
  ],
  "only": ["virtualbox-iso"]
},
{
  "type": "shell",
  "inline": [
"sudo sed -i 's/^PasswordAuthentication no/PasswordAuthentication 
yes/' /etc/ssh/sshd_config",
"sudo cat /etc/ssh/sshd_config"
  ],
  "only": ["virtualbox-iso"]
 }
  ],
  "post-processors": [
{
  "type": "vagrant",
  "output": "plos_{{.Provider}}_{{user `commit`}}_{{isotime 
\"2006-01-02-150405\"}}.box",
  "keep_input_artifact": true,
  "only": ["virtualbox-iso"]
}
  ]
}

The init.sh script just installs some packages and sets up salt to run. 
Then the final step is to flip that sshd config setting so we can login the 
first time to set things up in Vagrant. You can see I was cat'ing out the 
file to be sure it was getting changed, and it