What's the point of user_data?

44 views
Skip to first unread message

s...@integrichain.com

unread,
May 22, 2018, 1:00:42 AM5/22/18
to Packer
So I have a bash script that installs a few things before my ansible-local run within the provisioner block. My intial draft I had a shell provisioner that would run my bash script. It works fine and ansible runs fine. I learned about user_data_file and decided to move this initial shell script out of the provisioner and set it as a user_data_file. It doesn't seem to work because I have it installing ansible on the image Packer is building in order to run the ansible-local provisioner.

Does user_data_file run at the end before it snapshots the image or does it run BEFORE the provisioner starts?

Rickard von Essen

unread,
May 22, 2018, 7:22:57 AM5/22/18
to packe...@googlegroups.com
User data 1) is used by cloud-init 2). Cloud init is a service that executes early in the boot process and reads user-data (among other things) and can modify the VM's setup. It can add users and ssh-keys to allow connection via ssh. But it's not guaranteed to finish before sshd starts, so there is no strict order.

I sugest that you read the references, Google and get back if you get any more specific follow up questions. 


On 22 May 2018 at 07:00, <s...@integrichain.com> wrote:
So I have a bash script that installs a few things before my ansible-local run within the provisioner block. My intial draft I had a shell provisioner that would run my bash script. It works fine and ansible runs fine. I learned about user_data_file and decided to move this initial shell script out of the provisioner and set it as a user_data_file. It doesn't seem to work because I have it installing ansible on the image Packer is building in order to run the ansible-local provisioner.

Does user_data_file run at the end before it snapshots the image or does it run BEFORE the provisioner starts?

--
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/af009da8-6228-406a-8f72-53926c1d7a84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

s...@integrichain.com

unread,
May 22, 2018, 7:41:09 AM5/22/18
to Packer
Ok so it's actually the "user-data" I'm thinking of. So if i need it to run before I run my ansible playbook via the provisioner, that's not going to fly.


On Tuesday, May 22, 2018 at 7:22:57 AM UTC-4, Rickard von Essen wrote:
User data 1) is used by cloud-init 2). Cloud init is a service that executes early in the boot process and reads user-data (among other things) and can modify the VM's setup. It can add users and ssh-keys to allow connection via ssh. But it's not guaranteed to finish before sshd starts, so there is no strict order.

I sugest that you read the references, Google and get back if you get any more specific follow up questions. 

On 22 May 2018 at 07:00, <s...@integrichain.com> wrote:
So I have a bash script that installs a few things before my ansible-local run within the provisioner block. My intial draft I had a shell provisioner that would run my bash script. It works fine and ansible runs fine. I learned about user_data_file and decided to move this initial shell script out of the provisioner and set it as a user_data_file. It doesn't seem to work because I have it installing ansible on the image Packer is building in order to run the ansible-local provisioner.

Does user_data_file run at the end before it snapshots the image or does it run BEFORE the provisioner starts?

--
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.

Megan Marsh

unread,
May 22, 2018, 1:24:34 PM5/22/18
to packe...@googlegroups.com
You can install ansible via a shell provisioner before you run your ansible-local provisioner:

  "provisioners": [
    {
      "type": "shell",
      "inline": ["sudo apt-get -y update",
                "sudo apt-get -y install software-properties-common",
                "sudo apt-add-repository -y ppa:ansible/ansible",
                "sudo apt-get -y update",
                "sudo apt-get -y install ansible"]
    },
    {
      "type":  "ansible-local",
      "playbook_file": "../ansible/playbook.yml"
    }
  ]
Reply all
Reply to author
Forward
0 new messages