Ask Your Question
0

user_data script on AWS Windows Instance

asked 2015-09-02 12:19:12 -0500

r4hul gravatar image

updated 2015-09-03 15:53:13 -0500

I am trying to pass a user_data script with my puppet launch code to deploy an EC2 instance and send a powershell script to just do a basic task like creating a directory and a txt file. But nothing happens on my windows instance after launch. Here are the code snippets... First image is from yaml file being referenced by hiera, second and third from my main puppet code file:

image description

UPDATE: I renamed the file to test.ps1.erb and created it as a erb template but it still won't work. Also tried passing normal test.ps1 script without using template which also doesn't work. Am I doing something in a wrong way?

Referring to the example on github, I made a similar template test.erb (screenshot below) and that doesn't work either.

test.erb

image description

ANOTHER UPDATE: It only works if I assign template('module/test.erb') directly to user_data. For some reason it won't work if the same thing comes from the yaml file through Hiera. I have no idea why is it not going the second way... Please help!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-09-03 13:49:57 -0500

r4hul gravatar image

updated 2015-09-03 16:59:27 -0500

So there is nothing wrong with the template file I am using. There is something that I messed up with the path to the file because I am using Hiera and may be my puppet code is not able to see the location of that file.

There is some problem with assigning template() to a yaml key and then calling the whole thing. So here is what I did and it works:

  1. yaml file has a userdata key that stores just the location

    userdata: testarch/test.erb

  2. main puppet code file has a variable $userdata that gets the value from hiera()

    $userdata = hiera('userdata')

  3. user_data of the ec2_instance method gets the value as follows:

    user_data => template("$userdata")

Thanks!

edit flag offensive delete link more
1

answered 2015-09-02 20:56:57 -0500

Iristyle gravatar image

updated 2015-09-02 21:02:32 -0500

It would be helpful to see the PowerShell script to make sure it's formatted properly.

My guess is that you haven't properly enclosed it in XML tags as is required by AWS.

<powershell>
# code goes here
</powershell>

Please see the examples in the modules GitHub repository, particularly the Windows user_data template and the manifest demonstrating use of the template when provisioning a Windows node.

edit flag offensive delete link more

Comments

Thanks for the response. I have actually tried that way as well but it still doesn't work... Here is what I wrote in my file: <powershell> write-host "Creating directory and file" ni C:\test -type directory ni C:\test\sample.txt -type file -value "This file is created by puppet" </powershell>

r4hul gravatar imager4hul ( 2015-09-03 01:16:04 -0500 )edit

Please add the template contents to your question with the same formatting that you're using. I'm assuming everything isn't on a single line like that?

Iristyle gravatar imageIristyle ( 2015-09-03 12:36:08 -0500 )edit

It was formatted as in the screenshot I just added. Also, why won't puppet throw an error if the file wasn't successfully created on the instance. I don't see this script in the UserScript file on windows instance as I see it when I send the same code via EC2 console's user data method...

r4hul gravatar imager4hul ( 2015-09-03 13:15:10 -0500 )edit

I don't think there's any way for Puppet to detect the problem in question, unless you want Puppet to ensure that user_data is not an empty string?

Iristyle gravatar imageIristyle ( 2015-09-03 18:03:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-09-02 12:19:12 -0500

Seen: 556 times

Last updated: Sep 03 '15