Ansible:AnsibleUndefinedVariable:'ansible_eth1'

时间:2016-11-09 14:40:38

标签: amazon-web-services amazon-ec2 ansible virtual-machine

我正在尝试使用Ansible配置AWS EC2实例,但在某个任务中它会返回:

  

“AnsibleUndefinedVariable:'ansible_eth1'未定义”

我的问题是:什么是'ansible_eth1',我的意思是:我在哪里发现了这个该死的变量?我用谷歌搜索“我找到了ansible_eth1变量”这样的东西,但没有运气·

我的collectd.conf.j2是:

# For each instance where collectd is running, we define 
# hostname proper to that instance. When metrics from
# multiple instances are aggregated, hostname will tell 
# us were they came from.

Hostname "dash"

# Fully qualified domain name, false for our little lab
FQDNLookup false

# Plugins we are going to use with their configurations,
# if needed
LoadPlugin cpu

LoadPlugin df
<Plugin df>
        Device "/dev/sda1"
        MountPoint "/"
        FSType "ext4"
        ReportReserved true
</Plugin>

LoadPlugin interface
<Plugin interface>
        Interface "eth0"
        Interface "eth1"
        IgnoreSelected false
</Plugin>

LoadPlugin network
<Plugin network>
  <Server "{{ ansible_eth1.ipv4.address }}" "25826">
  </Server>
</Plugin>

LoadPlugin memory

LoadPlugin syslog
<Plugin syslog>
        LogLevel info
</Plugin>

LoadPlugin swap

<Include "/etc/collectd/collectd.conf.d">
        Filter "*.conf"
</Include>

我认为是这样,我希望这一点已经明确。

提前致谢

1 个答案:

答案 0 :(得分:0)

您的collectd.cong.j2正在使用未定义的变量ansible_eth1.ipv4.address。 您可以使用debug检查它:

- name: Display all variables/facts known for a host
  debug: var=hostvars[inventory_hostname]

您必须在库存中或在ansible接受的任何其他位置定义该变量。请看ansible documentation

而且,我认为你不应该在你的情况下对该变量使用ansible_前缀。