user_data for nova_compute module

103 views
Skip to first unread message

John Test

unread,
Apr 27, 2015, 7:37:45 AM4/27/15
to ansible...@googlegroups.com
Hello

I have a question regarding user_data parameter for nova_compute
http://docs.ansible.com/nova_compute_module.html

Is it possible to see some examples?

What I am trying to do:
Pass information to run commands / install software inside the instance after it is launched


Thanks!

John Test

unread,
Apr 30, 2015, 1:34:17 PM4/30/15
to ansible...@googlegroups.com
Figured it out thanks to sivel on IRC.
In case anyone else is wondering just do a lookup('file', 'filename')
The file called "filename" can be a bash script file, cloud init file, etc.
Make sure the file starts with the appropriate header such as
#!/bin/bash or #cloud-config etc.

Brian Coca

unread,
Apr 30, 2015, 2:38:25 PM4/30/15
to ansible...@googlegroups.com
lookup('pipe', 'script') might be more appropriate, it will succeed in
many cases that file will fail.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/bf3b0aad-643f-48cd-b9e0-ccf07d01daea%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

John Test

unread,
Apr 30, 2015, 7:58:43 PM4/30/15
to ansible...@googlegroups.com
pipe is failing on me

pb_set_proxy: "{{ lookup('pipe', 'proxy-set.sh') }}"

/bin/sh: 1: proxy-set.sh: not found
ERROR: lookup_plugin.pipe(proxy-set.sh) returned 127

I know it says not found but it is present and in same dir.


I actually have another problem

I am using 2 user_data parameters like this in the same nova_compute task

   user_data: "{{ lookup('file', 'proxy-set.sh') }}"
   user_data: "{{ lookup('file', 'misc-install.sh') }}"

Only the misc-install.sh is working and the proxy-set.sh is not.
What's the correct way to do this?

Thanks!

Matt Martz

unread,
Apr 30, 2015, 8:02:57 PM4/30/15
to ansible...@googlegroups.com
I don't really think pipe is what you need.  pipe executes a command and returns the result.  I think 'file' is still appropriate.

As far as your double user_data, you can only include one "blob" of data.  You could try concatenating the scripts such as:

user_data: "{{ lookup('file', 'proxy-set.sh') ~ '\n' ~ lookup('file', 'misc-install.sh') }}"


For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Brian Coca

unread,
Apr 30, 2015, 9:16:27 PM4/30/15
to ansible...@googlegroups.com
ah, misunderstood, thought you wanted data from executing the script,
not to upload the script itself as data.
> https://groups.google.com/d/msgid/ansible-project/CAD8N0v-y8bBt35cG3FVtH4LbWp7dpc9QRqu82jN2-Gnm-nR5pQ%40mail.gmail.com.

John Test

unread,
May 1, 2015, 1:02:13 AM5/1/15
to ansible...@googlegroups.com
Thanks Matt!
Reply all
Reply to author
Forward
0 new messages