Ask Your Question
0

create variable from file

asked 2015-12-28 15:12:58 -0500

Esity gravatar image

updated 2015-12-28 19:07:05 -0500

I am creating instances via google compute. the issue is I need to specific the IP in a config file. I have made it this far but am stuck.

I automatically create the external ip in a file ( /etc/ip) I need to reference that file to turn it into a variable to use in an ERB.

Any ideas?

Edit

here is all I want to accomplish. I have a config file that is automatically generated. inside that config file it has externalIp =

I want that to be filled in with the value from /opt/ip currently I have my erb template file like this externalIp = <%= @ip %>

If I set the variable in the class $ip to 5.5.5.5 then in that conf file externalIp = 5.5.5.5

What I cant figure out now is how to set $ip = /opt/ip

edit retag flag offensive close merge delete

Comments

I thought maybe to do something like this $test = generate("/bin/cat", "-A", "/opt/ip") which gives this error Failed to execute generator /bin/cat: Execution of '/bin/cat -A /opt/ip' return ed 1: /bin/cat: /opt/ip: No such f but when I run sudo -H -u puppet bash -c '/bin/cat -A /opt/ip' it works

Esity gravatar imageEsity ( 2015-12-28 19:49:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-12-28 17:23:56 -0500

lupin gravatar image

Without knowing the actual use case and when the variable will be require we can't provide real answer. You might want to check these custom function or custom facts or inline template or provide in your question an example.

edit flag offensive delete link more

Comments

updated the main section as it said i typed to much for a comment

Esity gravatar imageEsity ( 2015-12-28 19:07:28 -0500 )edit

generate and other customs functions are executed on master. If /opt/ip is located on node you can write a custom facts that will parse that file and turn the it into a facts.

lupin gravatar imagelupin ( 2015-12-29 05:30:32 -0500 )edit

/opt/ip is located on the node. so how do I write a custom fact on the server? do I use puppet to create that custom fact?

Esity gravatar imageEsity ( 2015-12-29 09:49:40 -0500 )edit

You can use puppet to upload custom facts to node (https://docs.puppetlabs.com/facter/3.1/custom_facts.html#executable-facts-----unix), custom fact should read /opt/ip and return it as key => value. Using puppet to manage your custom fact has drawback, custom fact will be use in second run.

Marek Maksimczyk gravatar imageMarek Maksimczyk ( 2015-12-29 15:18:44 -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-12-28 15:12:58 -0500

Seen: 409 times

Last updated: Dec 28 '15