Server&Network/Ansible
Ansible 비번 없이 로그인 하는 yaml 파일 만들기
하즈시
2021. 6. 22. 23:47
728x90
---
- name: ssh-keygen
hosts: Cent
gather_facts: no
tasks:
-
name: "ssh password"
connection: local
command: "ssh-keygen -b 2048 -t rsa -f /home/vagrant/.ssh/id_rsa -q -N ''"
#ansible server에서 ssh key 생성을 위해 local에서 실행
ignore_errors: yes
run_once: true
-
name: "import id_rsa.pub"
connection: local
command: "cat /home/vagrant/.ssh/id_rsa.pub"
register: id_pub
run_once: true
#msg: "{{ id_pub.stdout }}"
-
name: "add ansible-node authrized keys"
lineinfile:
dest: /home/vagrant/.ssh/authorized_keys
line: "{{ id_pub.stdout }}"
해당 파일을 돌려주면
처음에만 비번 입력하라고 하고
그 뒤에 명령어 사용시에는 비번없이 가능
참고
[Ansible] Authorized_keys 등록하기(SSH Key)
[Ansible] Authorized_keys 등록하기(SSH Key) Authorized Keys란? Ansible Server(Source)에서 Ansible Node(Destination) 접속 시도 시 계정에 대한 암호를 입력해야 합니다. 이러한 암호를 매번 입력하면 Ansi..
ossian.tistory.com
728x90