问题原文
原帖链接 · Nstevens · CC BY-SA 4.0
How can I get Ansible to populate the correct file when my /etc/ssh/sshd_config has AuthorizedKeysFile set to /etc/ssh/authorized_keys/%u? Ansible seems to ignore the setting and places keys in $HOME/.ssh/authorized_keys
playbook:
---
- hosts: all
vars:
vars_files:
- ../group_vars/ssh_root_authorized_keys.yml
gather_facts: false
tasks:
- name: Set up multiple authorized keys
authorized_key:
user: root
state: present
key: '{{ item.key }}'
with_items: "{{ root_auth_keys }}"
ssh_root_authorized_keys.yml
root_auth_keys:
- name: backup@host
key : "{{ lookup('file', '../group_vars/pubkeys/[email omitted]') }}"
- name: nagios@host
key : "{{ lookup('file', '../group_vars/pubkeys/[email omitted]') }}"
已采纳解答
原帖链接 · Gerald Schneider · CC BY-SA 4.0
From the documentation:
path: Alternate path to the authorized_keys file
tasks:
- name: Set up multiple authorized keys
authorized_key:
user: root
state: present
key: '{{ item.key }}'
path: '/etc/ssh/authorized_keys/root'
with_items: "{{ root_auth_keys }}"
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
