Insert Variable Values when loading a Cloud Config?

I asked a question on another site
(Does bare-metal coreos etcd2 support the templating feature of coreos-cloudinit? - Stack Overflow)
about loading a cloud config from nginx onto a bare-metal core-os
machine.

The question involves trying to have nginx fill in the variables for the
$private_ipv4 and $public_ipv4 when a config is loaded up. Does this
require that I use php-fpm to somehow recognize the machine sending the
request, and then fill in the variables when the cloud-config is
requested?

Posted at Nginx Forum:

On Mon, Jul 11, 2016 at 09:40:45AM -0400, leeand00 wrote:

Hi there,

The question involves trying to have nginx fill in the variables for the
$private_ipv4 and $public_ipv4 when a config is loaded up. Does this
require that I use php-fpm to somehow recognize the machine sending the
request, and then fill in the variables when the cloud-config is requested?

I think that the nginx side of the question is:

A file exists on the filesystem. A request is made for the matching
url. Can nginx return the file contents, making some textual
substitutions
in the file contents?

If that is the question, then the answers probably involves: does nginx
know what the desired substitutions are? (As in, where do the suitable
values for $private_ipv4 and $public_ipv4 come from?)

If nginx can know, then probably the sub_filter module
(Module ngx_http_sub_module) can help.

You made need to check that you can include a literal $ in the string
to replace, but that should be a straightforward enough test after you
know that nginx can know what the replacement strings are.

If sub_filter is not suitable, then you could use any other active
content
system (such as php-fpm) to do the work. The details will matter.

Good luck with it,

f

Francis D. [email protected]

This is just a guess, but probably a hashap…or maybe a DNS server that
assigns them statically. But I suppose CoreOS has to request it from
nginx,
so it could probably even just pull it out of the request.

Posted at Nginx Forum:

On Mon, Jul 11, 2016 at 09:24:11PM -0400, leeand00 wrote:

Hi there,

This is just a guess, but probably a hashap…or maybe a DNS server that
assigns them statically. But I suppose CoreOS has to request it from nginx,
so it could probably even just pull it out of the request.

When you can see what the request is, and what information it includes,
and when you can see how nginx-or-something-else can take that
information
and determine the correct public and private addresses to use, then you
may have enough information to configure sub_filter (or something else)
to return the content that you want.

Most of those missing pieces are not nginx-specific.

There might be someone here who knows about them; but if they are
CoreOS-specific, you may have better luck on a CoreOS list.

Good luck with it,

f

Francis D. [email protected]