我在远程主机上创建用户:
- name:将现有用户添加到服务器 用户: 名称:“{{item}}” 组:admin,prog generate_ssh_key:是的 ssh_key_bits:2048 ssh_key_file:.ssh / …
我想出了如何访问结果数组,循环遍历它,并设置键:
的 前代码: 强>
- name: Set authorized keys for users authorized_key: user: "{{ item }}" state: present key: #Need to access that generated list here, but how? with_items: - user1 - user2 - user3 - user4 - user5 - user6 - user7
的 工作代码 强>
- name: Set authorized keys for users authorized_key: user: "{{ item.name }}" #Grabs the username from each object state: present key: "{{ item.ssh_public_key }}" #Grabs the ssh key from each object loop: "{{ result.results | list }}" #Loops over the object array
这样可以为每个用户正确生成authorized_key文件。