2017-07-18 31 views
0

我想运行一个剧本,它对存储在host_vars中的变量执行。这是溶液布局:Ansible的手册不拾取主机变量

  • /host_vars/F5-测试
  • /库存/主机
  • /playbook.yml

这些文件的内容如下低点:

/库存/主机:

[f5-test] 
localhost 

/host_vars /主机

f5_user:user 
f5_password:password 
f5_server:server 

/playbook.yml

- name: Playbook 
    hosts: f5-test 
    gather_facts: no 
    gather_subset: no 

    tasks: 
    - name: Taks_01 
     tags: "bigip-node" 
     bigip_node: 
     server: "{{f5_server}}" 
     user: "{{f5_user}}" 
     password: "{{f5_password}}" 
     state: "present" 
     partition: "Common" 
     host: "10.20.30.40" 
     name: "F5_Node" 
     session_state: "enabled" 
     description: "description" 
     delegate_to: localhost 

ħ H但是,当我们执行以下命令:

须藤ansible-剧本playbook.yml -i库存/主机-vvvv

我得到以下错误:

task path: /home/dev/ansible/playbook.yml:9 
fatal: [localhost]: FAILED! => { 
    "failed": true, 
    "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'f5_server' is undefined\n\nThe error appears to have been in '/home/dev/ansible/playbook.yml': line 9, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Task_01\n ^here\n" 
} 

知道为什么它没有被拾起?我用与F5完全相同的结构建立了我的项目,可以找到here

谢谢!

+0

请仔细阅读你的问题并修复明显的不一致。很难分辨出在编写问题时以及在设置文件时出现了哪些错误。 – techraf

回答

3

在您的示例主机文件f5-test是一个组,而不是主机。

所以,把你的变量为group_vars文件:./group_vars/f5-test.yml:

f5_user: user 
f5_password: password 
f5_server: server 
+0

与F5的Ansible贡献者证实康斯坦丁的答案是正确的。 – Chase

-1

host_vars目录需要位于与您的库存相同的文件夹中。所以移动/host_vars/f5-test/inventory/host_vars/f5-test。请查看best practices page了解更多信息。

+0

我按照您的建议移动了该文件夹,但问题依然存在。同样通过这个逻辑,f5的例子也不起作用。 https://github.com/F5Networks/f5-ansible/tree/devel/examples/000-getting-started – jonatzin

+0

您还需要将文件名从'f5-test'更改为'localhost',因为“f5测试“是你的组名。如果需要,您可以添加一个'group_vars'目录并将'f5-test'移动到那里。 – kfreezy