Hi
I have a usecase in which I want to pass some parameters to a module only
if I have a variable defined with value for them. If I don't, I want the
module to use its default value for these parameters. In ansible 1.5.5 (I
know, old as hell), I could do this:

module: {% if value is defined %}param={{value}}{% endif %}

However later versions of ansible seem to have removed it due to security
concerns (which I don't understand, but that's a different topic :) ). How
should I go about doing that in Ansible 1.7? Do I have to keep my own
default values?

Thanks

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8aa00f58-62f8-4bc4-a243-306dcaebbefc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • James Cammarata at Sep 17, 2014 at 2:40 pm
    Hi Hagai,

    We've recently added the ability to omit parameters if they are not defined
    via the "| default(omit)" filter. The documentation regarding this is here:
    http://docs.ansible.com/playbooks_variables.html#omitting-undefined-variables-and-parameters.
    This will be included in 1.8, so for now with 1.7 you will still have to
    default the parameter to some value if it is not defined.

    The reason we now disallow what you're doing in your example is the fact
    that someone could try to inject additional parameters into the module
    arguments via variables, so Ansible now expects a consistent number of
    parameters both before and after the templating of module params is done.

    Let us know if you have any further questions regarding this.

    Thanks!
    On Wed, Sep 17, 2014 at 9:14 AM, Hagai Kariti wrote:

    Hi
    I have a usecase in which I want to pass some parameters to a module only
    if I have a variable defined with value for them. If I don't, I want the
    module to use its default value for these parameters. In ansible 1.5.5 (I
    know, old as hell), I could do this:

    module: {% if value is defined %}param={{value}}{% endif %}

    However later versions of ansible seem to have removed it due to security
    concerns (which I don't understand, but that's a different topic :) ). How
    should I go about doing that in Ansible 1.7? Do I have to keep my own
    default values?

    Thanks

    --
    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-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/8aa00f58-62f8-4bc4-a243-306dcaebbefc%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/8aa00f58-62f8-4bc4-a243-306dcaebbefc%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    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-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAMFyvFjC5wTxKZ2rozu_y55zKkU%3Dy-p9MBdUFPcmPe8XsdwvcQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Hagai Kariti at Sep 17, 2014 at 2:59 pm

    On Wednesday, September 17, 2014 5:41:03 PM UTC+3, James Cammarata wrote:
    Hi Hagai,

    We've recently added the ability to omit parameters if they are not
    defined via the "| default(omit)" filter. The documentation regarding this
    is here:
    http://docs.ansible.com/playbooks_variables.html#omitting-undefined-variables-and-parameters.
    This will be included in 1.8, so for now with 1.7 you will still have to
    default the parameter to some value if it is not defined.
    Ooh, that's cool.

    The reason we now disallow what you're doing in your example is the fact
    that someone could try to inject additional parameters into the module
    arguments via variables, so Ansible now expects a consistent number of
    parameters both before and after the templating of module params is done.
    I guess I'm not that afraid of weird variable values. Seems fair to enforce
    this, though.

    Thanks a lot!
    Let us know if you have any further questions regarding this.

    Thanks!

    On Wed, Sep 17, 2014 at 9:14 AM, Hagai Kariti <hka...@gmail.com
    <javascript:>> wrote:
    Hi
    I have a usecase in which I want to pass some parameters to a module only
    if I have a variable defined with value for them. If I don't, I want the
    module to use its default value for these parameters. In ansible 1.5.5 (I
    know, old as hell), I could do this:

    module: {% if value is defined %}param={{value}}{% endif %}

    However later versions of ansible seem to have removed it due to security
    concerns (which I don't understand, but that's a different topic :) ). How
    should I go about doing that in Ansible 1.7? Do I have to keep my own
    default values?

    Thanks

    --
    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 <javascript:>.
    To post to this group, send email to ansible...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/8aa00f58-62f8-4bc4-a243-306dcaebbefc%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/8aa00f58-62f8-4bc4-a243-306dcaebbefc%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    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-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f11eb940-7bc0-4244-8704-2ce63b78db0f%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • David Wittman at Jul 10, 2015 at 3:34 pm
    The documentation for this feature has been moved
    to https://docs.ansible.com/playbooks_filters.html#omitting-undefined-variables-and-parameters.
    On Wednesday, September 17, 2014 at 9:41:03 AM UTC-5, James Cammarata wrote:

    Hi Hagai,

    We've recently added the ability to omit parameters if they are not
    defined via the "| default(omit)" filter. The documentation regarding this
    is here:
    http://docs.ansible.com/playbooks_variables.html#omitting-undefined-variables-and-parameters.
    This will be included in 1.8, so for now with 1.7 you will still have to
    default the parameter to some value if it is not defined.

    The reason we now disallow what you're doing in your example is the fact
    that someone could try to inject additional parameters into the module
    arguments via variables, so Ansible now expects a consistent number of
    parameters both before and after the templating of module params is done.

    Let us know if you have any further questions regarding this.

    Thanks!

    On Wed, Sep 17, 2014 at 9:14 AM, Hagai Kariti <hka...@gmail.com
    <javascript:>> wrote:
    Hi
    I have a usecase in which I want to pass some parameters to a module only
    if I have a variable defined with value for them. If I don't, I want the
    module to use its default value for these parameters. In ansible 1.5.5 (I
    know, old as hell), I could do this:

    module: {% if value is defined %}param={{value}}{% endif %}

    However later versions of ansible seem to have removed it due to security
    concerns (which I don't understand, but that's a different topic :) ). How
    should I go about doing that in Ansible 1.7? Do I have to keep my own
    default values?

    Thanks

    --
    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 <javascript:>.
    To post to this group, send email to ansible...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/8aa00f58-62f8-4bc4-a243-306dcaebbefc%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/8aa00f58-62f8-4bc4-a243-306dcaebbefc%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    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-project+unsubscribe@googlegroups.com.
    To post to this group, send email to ansible-project@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d97bba1f-cb06-4e5d-ab16-9c83c2e5dba0%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedSep 17, '14 at 2:14p
activeJul 10, '15 at 3:34p
posts4
users3

People

Translate

site design / logo © 2022 Grokbase