【发布时间】:2014-11-29 22:51:07
【问题描述】:
我已经编写了一个 ansible 脚本来从远程服务器中删除 SSH 密钥:
---
- name: "Add keys to the authorized_keys of the user ubuntu"
user: ubuntu
hosts: www
tasks:
- name: "Remove key #1"
authorized_key: user=ubuntu key="{{ item }}" state=absent
with_file:
- id_rsa_number_one.pub
- name: "Remove key #2"
authorized_key: user=ubuntu key="{{ item }}" state=absent
with_file:
- id_rsa_number_two.pub
...
将每个文件添加为不同的任务是荒谬的,所以我尝试使用with_fileglob:
- name: "Remove all keys at once"
authorized_key: user=ubuntu key="{{ item }}" state=absent
with_fileglob:
- /Users/adamatan/ansible/id_rsa*.pub
但这会失败,如下所示:
失败:[www.example.com] => (item=/Users/adamatan/ansible/id_rsa_one.pub) => {"失败": true, "item": "/Users/adamatan/ansible/id_rsa_one.pub"} msg: 无效密钥 指定:/Users/adamatan/ansible/id_rsa_one.pub
使用唯一任务成功删除了相同的密钥文件,但当它是 fileglob 的一部分时失败。
如何使用 ansible 批量添加或删除 SSH 密钥?
【问题讨论】:
标签: ssh batch-processing ssh-keys ansible ansible-playbook