これに触発された役割を作成しようとしています: ansible-cassandra。
このロールには、 variable のデフォルト値がありますcassandra_network_iface
。
cassandra_network_iface: eth0
そして、それを介してそれを使用するテンプレートファイルcassandra.yaml.j2hostvars
:
...
- seeds: "{% for host in groups[cassandra_ansible_groupname] %}{{hostvars[host]['ansible_' + hostvars[host]['cassandra_network_iface']]['ipv4']['address']}}{% if not loop.last %},{% endif %}{% endfor %}"
...
このテンプレート ファイルをタスクで使用すると、次のようになります。
- name: configure...
template: >-
src=cassandra.yaml.j2
dest=/tmp/cassandra.yaml
mode=0644
このエラーがあります:
fatal: [...]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'cassandra_network_iface'"}
問題は、変数cassandra_network_iface
がスコープに定義されていないことですhostvars[host]
(デバッグタスクで確認しました)。それ以外の場合は、変数を直接使用できます。
cassandra_network_iface
私の質問:を通じて変数に到達する方法はありますhostvars
か?
注:ansible 2.1および2.2で試しました