gpt4 book ai didi

variables - Ansible 剧本不会获取主机变量

转载 作者:行者123 更新时间:2023-12-02 08:12:32 27 4
gpt4 key购买 nike

我正在尝试运行一个针对存储在 host_vars 中的变量执行的剧本。这是解决方案布局:

  • /host_vars/f5-test
  • /inventory/hosts
  • /playbook.yml

文件内容如下:

/库存/主机:

[f5-test]
localhost

/host_vars/hosts

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

但是当我们执行以下命令时:

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"
}

知道为什么它没有被拾取吗?我在 F5 ansible 示例中找到的相同结构中设置我的项目,可以找到 here .

谢谢!

最佳答案

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

因此将您的变量放入 group_vars 文件中:./group_vars/f5-test.yml:

f5_user: user
f5_password: password
f5_server: server

关于variables - Ansible 剧本不会获取主机变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45167606/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com