jon*_*zin 2 variables f5 ansible
我正在尝试运行一个执行存储在host_vars中的变量的剧本.这是解决方案布局:
文件内容如下:
/存货/主机:
[f5-test]
localhost
Run Code Online (Sandbox Code Playgroud)
/ host_vars /主机
f5_user:user
f5_password:password
f5_server:server
Run Code Online (Sandbox Code Playgroud)
/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
Run Code Online (Sandbox Code Playgroud)
但是,当我们执行以下命令时:
sudo ansible-playbook playbook.yml -i inventory/hosts -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"
}
Run Code Online (Sandbox Code Playgroud)
知道为什么它没被拿起来吗?我将项目设置在F5 ansible示例中的相同结构中,可以在此处找到.
谢谢!
在您的示例中,hosts文件f5-test
是一个组,而不是主机.
所以将变量放入group_vars文件中:./ group_vars/f5-test.yml:
f5_user: user
f5_password: password
f5_server: server
Run Code Online (Sandbox Code Playgroud)