Comments (9)
@sivel checked the module, it does not cast, so native is really your only avenue in this specific case.
from ansible.
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.
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.
- Enable jinja2 native, may have other adverse affects
- Follow the k8s module examples of reading the
defintion
usinglookup('template', ...)
- Don't use variables that refer to templates using other variables (just use
ldap_port
instead ofopenldap_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.
or just add |int
filter at consumption to cast it
from ansible.
@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.
you should not even need to do that if port is defined as an integer, the module itself will cast it
from ansible.
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.
yes, IF the port field is defined as an integer
from ansible.
Closing per above.
If you have further questions please stop by IRC or the mailing list:
- IRC: #ansible on irc.libera.chat
- mailing list: https://groups.google.com/forum/#!forum/ansible-project
See this page for a complete and up to date list of communication channels and their purposes:
from ansible.
Related Issues (20)
- Server not found in Kerberos database HOT 2
- Changes to linux.py for setup module to return more relevant information for s390 HOT 2
- `ansible.builtin.package_facts` returns an empty list when `manager=auto` HOT 7
- with_items using jinja2 no longer working after Ansible 2.16.4(and 6) upgrade. HOT 3
- `git` module: `Failed to init/update submodules: warning: could not look up configuration 'remote.origin.url'` HOT 9
- "Expecting value: line 1 column 1 (char 0)" -- JSONDecodeError("Expecting value", s, err.value) from None HOT 4
- ansilbe become user with rootsh support HOT 2
- task timeout failure should indicate timeout for programatic use HOT 3
- When fatal: happens when using iteration, all results are lost even if ignore_errors is true HOT 2
- Enable Logdna callback plugin to pass in custom log ingestion url HOT 1
- template module doesn't return a backup file HOT 7
- I cannot connect to a single server from the provider hetzner when the servers are in recovery mode HOT 1
- ansible.builtin.command not passing args to useradd correctly with argv parameter HOT 2
- handlers not fired when using roles HOT 8
- become_method "ansible.builtin.sudo" is not supported HOT 3
- Displaying file information for include_tasks when using the ansible-playbook command with the --list-tasks option HOT 5
- ansible-galaxy collection updates leave old dirs behind HOT 1
- service_facts returns non-existent services HOT 4
- Can ansible produce friendly messages? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible.