The problem is that cannot nest jinja brackets inside of brackets. Your
following example:
{{ ansible_hostname | regex_replace("^{{service}}-{{site}}-", '') }}
Should probably be:
{{ ansible_hostname | regex_replace("^" + service + "-" + site + "-", '')
}}
Inside of {{ }} variables are already expanded.
On Tuesday, December 2, 2014, Josh Smift <[email protected]> wrote:
> I have some variables like 'service', which can be "abc" or "xyz", and
> 'site', which can be "bos" or "sfo", on different hosts. I have hosts
> whose FQDNs are like service-site-thing-N.site.service.care.com, which
> have those those variables set accordingly, in a group like 'things'.
>
> My use case is that I want to create CNAME records, using the route53
> module, for names like thing-N.site.service.care.com, so that if you're on
> a host with site.service.care.com in its resolv.conf search path, you can
> refer to "thing-N" and have that resolve to service-site-thing-N.
>
> For now, to take the route53 aspect out of the equation (I just mentioned
> that for context), I'm just debugging, and it works if I hardcode the
> services and sites, but not if I try to use the variables.
>
> Here's a playbook:
>
> - hosts: things
>
> vars: { service="abc", site="bos" }
>
> tasks:
> - debug: msg={{ ansible_hostname | regex_replace("^abc-bos-", '') }}
> - debug: msg={{ ansible_hostname |
> regex_replace("^{{service}}-{{site}}-", '') }}
>
> Here's what that does:
>
> TASK: [debug msg={{ ansible_hostname | regex_replace("^abc-bos-", '')
> }}] *****
> ok: [abc-bos-thing-01] => {
> "msg": "thing-01"
> }
> ok: [abc-bos-thing-02] => {
> "msg": "thing-02"
> }
>
> TASK: [debug msg={{ ansible_hostname |
> regex_replace("^{{service}}-{{site}}-", '') }}] ***
> ok: [abc-bos-thing-01] => {
> "msg": "abc-bos-thing-01"
> }
> ok: [abc-bos-thing-02] => {
> "msg": "abc-bos-thing-02"
> }
>
> I was hoping the second one would be the same as the first. I tried a
> couple of variations on the syntax of the regex_replace in the second
> case, but no luck.
>
> I have the same problem if I try to use the
>
> {{ ansible_hostname | regex_replace("^{{service}}-{{site}}-", '') }}
>
> construction when I call the route53 module -- the regexp isn't actually
> replaced.
>
> Is there another/better way to do this?
>
> -Josh ([email protected] <javascript:;>)
>
>
>
> This email is intended for the person(s) to whom it is addressed and may
> contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized
> use, distribution, copying, or disclosure by any person other than the
> addressee(s) is strictly prohibited. If you have received this email in
> error, please notify the sender immediately by return email and delete the
> message and any attachments from your system.
>
> --
> 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 [email protected] <javascript:;>.
> To post to this group, send email to [email protected]
> <javascript:;>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/21630.10549.573264.896397%40gargle.gargle.HOWL
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v_Fjw89vF8eCsf_6tZj4HWFt4POUgomoTpZ8TzMoeisLA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.