我的ansible playbook存在一些问题,没有添加正确的变量。这是任务。
#Change name: to be the name of whatever group you want to add
- name: Add new group if necessary
group:
name: "{{ group_name }}"
state: present
# Change name: to be the name of the user you wish to add.
- name: Manage user accounts
user: name={{ item }} state=present group={{ group_name }}
with_items: "{{ users }} "
以下是变量文件
---
users:
- test1
- test2
- test3
group_name:
- developers
出于某种原因,当我运行它时,它会创建组并将其命名为this '开发人员'
然后,该剧的添加用户部分实际上正在寻找一个完全不同的组名[just]
查看输出失败。
PLAY [users] ******************************************************************
GATHERING FACTS ***************************************************************
ok: [172.17.51.202]
TASK: [user-manage | Add new group if necessary] ******************************
changed: [172.17.51.202]
TASK: [user-manage | Manage user accounts] ************************************
failed: [172.17.51.202] => (item=test1) => {"failed": true, "item": "test1"}
msg: Group [developers] does not exist
failed: [172.17.51.202] => (item=test2) => {"failed": true, "item": "test2"}
msg: Group [developers] does not exist
failed: [172.17.51.202] => (item=test3) => {"failed": true, "item": "test3"}
msg: Group [developers] does not exist
FATAL: all hosts have already failed -- aborting
这是它实际创建的组。 我无法弄清楚为什么他们都在寻找不同的变量而且实际上我都没有指定任何变量。
有什么想法吗?
回应Petro:
我将它从列表更改为单数变量
---
users:
- test1
- test2
- test3
group_name: developers
我仍然收到此错误
failed: [172.17.51.202] => (item=test1) => {"failed": true, "item": "test1"}
msg: Group [developers] does not exist
failed: [172.17.51.202] => (item=test2) => {"failed": true, "item": "test2"}
msg: Group [developers] does not exist
failed: [172.17.51.202] => (item=test3) => {"failed": true, "item": "test3"}
msg: Group [developers] does not exist
FATAL: all hosts have already failed -- aborting
所以这不起作用。还有其他想法吗?
编辑2:
Petro实际上做了工作。抱歉。我搞砸了。你的答案是正确的。
非常感谢!
答案 0 :(得分:0)
您将“group_name”设为列表而不是单个值。将您的vars文件更改为:
group_name: developers
它应该有效