有一些烦人的问题,我无法弄清楚。
这是我的代码。 如果我完全注释掉组和variables,一切正常。 但是,这是吐出下面的错误。
它基本上告诉我那个组不存在。 在这个例子中说msg:“Group”“all”不存在。 我不知道我需要做什么来解决这个问题。
- name: Add new group if it doesn't exist already group: name: "{{ group }}" when: group is defined - name: Add multiple users user: name: "{{ item.0 }}" comment: "{{item.1 }}" uid: "{{ item.2 }}" group: "{{ group }}" groups: "{{ groups }}" append: yes with_together: - "{{ name }}" - "{{ comment }}" - "{{ uid }}" - "{{ group }}" And variable file: name: - test1 - test2 comment: - "comment1" - "comment2" uid: - 150 - 151 group: sudo groups: - admin - test However, now I am receiving this error. failed: [127.0.0.1] => (item=[u'test1', u'comment1', 150, u'sudo']) => {"failed": true, "invocation": {"module_args": {"append": true, "comment": "comment1", "createhome": true, "expires": null, "force": false, "generate_ssh_key": null, "group": "sudo", "groups": "{'ungrouped': ['127.0.0.1'], 'all': ['127.0.0.1']}", "home": null, "login_class": null, "move_home": false, "name": "test1", "non_unique": false, "password": null, "remove": false, "shell": null, "skeleton": null, "ssh_key_bits": "2048", "ssh_key_comment": "ansible-generated on ubuntu-512mb-sfo1-01", "ssh_key_file": null, "ssh_key_passphrase": null, "ssh_key_type": "rsa", "state": "present", "system": false, "uid": "150", "update_password": "always"}, "module_name": "user"}, "item": ["test1", "comment1", 150, "sudo"], "msg": "Group 'all': ['127.0.0.1']} does not exist"} failed: [127.0.0.1] => (item=[u'test2', u'comment2', 151, None]) => {"failed": true, "invocation": {"module_args": {"append": true, "comment": "comment2", "createhome": true, "expires": null, "force": false, "generate_ssh_key": null, "group": "sudo", "groups": "{'ungrouped': ['127.0.0.1'], 'all': ['127.0.0.1']}", "home": null, "login_class": null, "move_home": false, "name": "test2", "non_unique": false, "password": null, "remove": false, "shell": null, "skeleton": null, "ssh_key_bits": "2048", "ssh_key_comment": "ansible-generated on ubuntu-512mb-sfo1-01", "ssh_key_file": null, "ssh_key_passphrase": null, "ssh_key_type": "rsa", "state": "present", "system": false, "uid": "151", "update_password": "always"}, "module_name": "user"}, "item": ["test2", "comment2", 151, null], "msg": "Group 'all': ['127.0.0.1']} does not exist"}
问题是variables名称相冲突。 groups是一个保留variables,拥有库存中的组。 而且all都是自动生成的组,其中包含您广告资源的所有主机。
从文档 :
即使你自己没有定义它们,Ansible也会自动为你提供一些variables。 其中最重要的是
hostvars,group_names和groups。 用户不应使用这些名称,因为它们是保留的。environment也是保留的。
和
groups是清单中所有组(和主机)的列表。 这可以用来枚举组中的所有主机。
只需重命名你的variables,它应该工作。 通常,将angular色的所有variables与angular色名称前缀是一个好主意。 如果您使用第三方angular色(例如来自Ansible Galaxy)来避免冲突,这变得更加重要。 所以,而不是groups可以使用myrole_groups ,可以肯定,永远不会有冲突。