Comments (4)
@collinglass In defaults, it says it has to be a List of dict (i.e. {zookeeper_hosts:[{host:,id:},{host:,id:},...]})
But I actually came here because I am having trouble dynamically creating (in jinja) a variable that holds a List of dict. The Ansible issue #10098 suggest that this is currently a bug in Ansible?
Is it possible to do this? Or should this project change to a different form of host specification?
This is some debug code I was using, which seems like it should work, except that Ansible is treating it as a string:
- debug: var="
{% set hosts = [] %}
{% for node in groups.tag_zookeeper_master %}
{% if hosts.append({
'host':hostvars[node]['ansible_default_ipv4']['address'],
'id':hostvars[node]['os__info']['metadata']['zookeeper_id']
})%}
{% endif %}
{% endfor %}
{{ hosts }}"
From which I get:
"var": {
" [{'host': '172.16.54.14', 'id': u'1'}, {'host': '172.16.54.13', 'id': u'3'}, {'host': '172.16.54.12', 'id': u'2'}]": " [{'host': '172.16.54.14', 'id': u'1'}, {'host': '172.16.54.13', 'id': u'3'}, {'host': '172.16.54.12', 'id': u'2'}]"
}
Is there a better way to do this?
from ansible-zookeeper.
@collinglass @hinchliff This is how I did:
- hosts: zookeepers
gather_facts: no
vars:
zookeeper_hosts: "
{%- set ips = [] %}
{%- for zk in groups['zookeepers'] %}
{{- ips.append(dict(host=zk, id=loop.index)) }}
{%- endfor %}
{{- ips -}}
"
tasks:
- debug: var=zookeeper_hosts
What I have found out is I had to use {{- ips.append... }}
(note the {{
) and use {{- ips -}}
to make the assignment working. The dashes "-" are telling Jinja to strip leading or remaining white spaces when evaluating template. http://jinja.pocoo.org/docs/dev/templates/#whitespace-control
TASK [debug var=zookeeper_hosts] ***********************************************
ok: [zookeeper03.domain.net] => {
"changed": false,
"zookeeper_hosts": [
{
"host": "zookeeper01.domain.net",
"id": 1
},
{
"host": "zookeeper02.domain.net",
"id": 2
},
{
"host": "zookeeper03.domain.net",
"id": 3
}
]
}
from ansible-zookeeper.
just fyi, I removed ".host" like below snippets(last 3line) in https://github.com/AnsibleShipyard/ansible-zookeeper/blob/master/templates/zoo.cfg.j2 then variable inventory_hostname
are iterated(multiple hosts ok) instead but by design seems to be as described.
{% for server in zookeeper_hosts %}
server.{{loop.index}}={{server}}:2888:3888
{% endfor %}
from ansible-zookeeper.
@ryoichitaniguchi @collinglass role now support both hash lists and array of hosts https://github.com/AnsibleShipyard/ansible-zookeeper/releases/tag/v0.9.2
from ansible-zookeeper.
Related Issues (20)
- Where does {{ zoo_id }} gets the value from? HOT 7
- Debian/Ubuntu tasks setup outdated zookeeper (ubuntu 14.04 repos latest version is 3.4.5) HOT 14
- tarball folder (/opt/src) is hardcoded and thus not configurable HOT 8
- [New Feature] configurable autopurge for zookeeper snapshots and logs HOT 1
- Cluster of several Zookeepers HOT 4
- The conditional check 'etc_init.stat.exists == true' failed when running with tag deploy HOT 2
- Missing option to pass autopurge configuration
- fix ansible-lint warnings HOT 1
- [New Feature] Testing with molecule (in docker containers)
- data_dir & log_dir not properly initialized for debian/ubuntu (non tarball deployment) HOT 3
- systemd - ZK starting up before the network is ready and available after a server reboot HOT 1
- zookeeper version 3.4.9 is unavailable HOT 2
- hard coded /var/log/zookeeper in templates/zookeeper.conf.j2 HOT 1
- I want to change zookeeper_url in china, but i cannot! HOT 2
- please update version to 0.23 on galaxy.ansible.com
- Automatically Install for Dependencies
- Write ahead logs are written into /var/log by default which is surprising
- Version format incompatability HOT 1
- The conditional check 'not zookeeper_debian_systemd_enabled' failed.
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-zookeeper.