我想在服务器上创建私钥和公钥,当我手动执行时,它要求我按“输入”三次并需要选择“y”一次。我可以使用ansible运行相同的命令吗?如果是,如何管理我们在服务器上运行时手动按下的“输入”。任何帮助都会很棒。
下面是我试过的剧本
- hosts: localhost
tasks:
- name: "Run ssh commands to create new ssh keys"
shell: ssh-keygen -f /home/dp794d/id_rsa -t rsa -q -N ""
args:
creates: /home/dp794d/.ssh/id_rsa
with_lines: cat "/home/capio/ansible/pmossWipm/day1/logs/testIP.txt"
我收到以下错误 -
failed: [localhost] (item=130.6.50.132) => {"changed": true, "cmd": "ssh-keygen -f /home/dp794d/.ssh/id_rsa -t rsa -q -N \"\"", "delta": "0:00:00.248041", "end": "2017-04-26 14:41:36.361705", "failed": true, "item": "130.6.50.132", "rc": 1, "start": "2017-04-26 14:41:36.113664", "stderr": "open /home/dp794d/.ssh/id_rsa failed: Permission denied.", "stdout": "Saving the key failed: /home/dp794d/.ssh/id_rsa.", "stdout_lines": ["Saving the key failed: /home/dp794d/.ssh/id_rsa."], "warnings": []}
答案 0 :(得分:1)
似乎你有一个双重问题
Permission denied
到/home/dp794d/.ssh/id_rsa
become:
来修复此上下文不匹配。键盘输入
ssh-keygen
可以使用-N new_passphrase
选项以非交互方式运行。尝试:
ssh-keygen -t rsa -N '' -f foo.rsa
注意:尝试使用单引号或双引号,直到获得所需的效果。