当我在 ansible 1.9.1 中执行以下操作时,它将每个 _individual_ 每用户密钥视为独占,而不是将每个用户密钥的 _group_ 视为独占。 因此,只有最后指定的每用户密钥可用。
- name: sync all users keys
authorized_key: user={{item.0.name}} key='{{item.1}}' state=present exclusive=yes
with_subelements:
- users
- keys
这是预期的,您正在运行模块 X 次,每次都具有独占性(X == 项目数)。
你好!
非常感谢您提交给 Ansible。 它真诚地对我们意义重大。
我们认为您提交的罚单有点被误解了,因为有一件事与陈述的有点不同。
将来,这可能是更适合用户列表的主题,如果您需要有关上述内容的更多帮助,也可以在此处发布。
再次感谢您对此以及您对 Ansible 的兴趣!
我已经通过一个中间步骤解决了这个问题。 像这样
# Read each file and split by newline, allowing for multiple keys per file
- name: Assemble keys
set_fact:
key_item: "{{ lookup('file', role_path + '/files/' + item).split('\n') }}"
with_items:
- bob.pub
- fred.pub
- barney.pub
register: keys
# Select each key, joining it again and join all keys. Internally the ansible
# module will then split the string by newline and work at each one. This is
# the only way exclusive works with a list of keys.
- name: Distribute operations ssh-keys to root
authorized_key:
key : "{{ keys.results|selectattr('ansible_facts','defined')|map(attribute='ansible_facts.key_item')|map('join', '\n')|join('\n') }}"
manage_dir : yes
state : present
user : root
exclusive : yes
最有用的评论
我已经通过一个中间步骤解决了这个问题。 像这样