Robert_Bryant
Mission Specialist
Mission Specialist
  • 127 Views

Confusion on use of ansible_managed to mark a file

In a Jinja2 template, we probably want to mark whatever file we're creating by rendering the template, so making sure the string ansible_managed is present is the point of this question. Of course we can edit what is returned by ansible_managed in ansible.cfg; i.e. we could make it say Hey hoss, don't bother editing this file, please (rather than ansible_managed, Ansible managed or whatever).

Now, the question: what's the difference between

{{ ansible_managed }}   and   # {{ ansible_managed }}

?

Edit: perhaps the question isn't clear... I've seen both of these in the RH294 video lecture/ text. I'd think that it would be preferred that any resulting file would have this clearly marked as a comment with the # sign, with    # {{ ansible_managed }}   so as not to be parsed and interpreted inadvertently by a later process...

Ch. 5, p. 199 shows an example template file with    # {{ ansible_managed }}   at the very top. Clear. Good. Ok. On the very next page, the text says:

To include the ansible_managed string inside a Jinja2 template, use the following syntax:

{{ ansible_managed }}

See my confusion and resulting frustration?

Now... if we want any template we use anywhere, that is subject to a particular ansible.cfg file, to have the # sign included we can set the directive in ansible.cfg to do it anywhere a template gets rendered, with:

ansible_managed = Ansible managed     (but we could use my southern US vernacular example above on the right side of that key / value pair, or any free-form text desired). That's also totally clear, but maybe I don't want that tag in every file created from a j2 template. So the manual method I'd prefer is to include the # sign, unless the rendering process adds it automatically.

Anyone?

Labels (1)
0 Kudos
0 Replies
Join the discussion
You must log in to join this conversation.