Code Monkey home page Code Monkey logo

Comments (9)

bcoca avatar bcoca commented on June 2, 2024 1

@sivel checked the module, it does not cast, so native is really your only avenue in this specific case.

from ansible.

ansibot avatar ansibot commented on June 2, 2024

Files identified in the description:

None

If these files are incorrect, please update the component name section of the description or use the component bot command.

from ansible.

sivel avatar sivel commented on June 2, 2024

This is expected without having jinja2 native enabled: https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-jinja2-native

The historical integration can only produce the following python data types:

  • dict
  • list
  • set
  • bool
  • str

Any other data type emitted from a single templating operation can only result in a str. This is why you see that type_debug indicates the type as being an int but the result of the templating operation results in a str.

I should note that we do have a shortcut in the code, that if the variable referenced is singular, we can directly return it's real value, however using variables that refer to other variables prevents this functionality.

You have a few options.

  1. Enable jinja2 native, may have other adverse affects
  2. Follow the k8s module examples of reading the defintion using lookup('template', ...)
  3. Don't use variables that refer to templates using other variables (just use ldap_port instead of openldap_port)

Note: When using lookup('template') you will not have to quote the jinja values, as that is working around a YAML "limitation", so it would just be: port: {{ openldap_port }}

from ansible.

bcoca avatar bcoca commented on June 2, 2024

or just add |int filter at consumption to cast it

from ansible.

msch-ibm avatar msch-ibm commented on June 2, 2024

@bcoca Not sure what you mean with "at consumption". You mean at the point I am passing the variable to the module using it's value? Because that doesn't work in my case:

- name: Create service
  k8s:
    state: present
    definition:
      kind: Service
      metadata:
        name: "openldapservice"
        namespace: "thenamespace"
      spec:
        ports:
          - name: "openldapport"
            protocol: TCP
            port: "{{ openldap_port | int }}" # doesn't work
            targetPort: "openldapport"

from ansible.

bcoca avatar bcoca commented on June 2, 2024

you should not even need to do that if port is defined as an integer, the module itself will cast it

from ansible.

msch-ibm avatar msch-ibm commented on June 2, 2024

Ok, but neither works (cast or not) when defining openldap_port as I did in the example I described (as reference to ldap_port, which is defined as integer). Are you suggesting that this should work, even with jinja2 native disabled?

from ansible.

bcoca avatar bcoca commented on June 2, 2024

yes, IF the port field is defined as an integer

from ansible.

mkrizek avatar mkrizek commented on June 2, 2024

Closing per above.

If you have further questions please stop by IRC or the mailing list:

See this page for a complete and up to date list of communication channels and their purposes:

from ansible.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.