728x90
authorized_keys란
- 인증된 키
- 이미 사용 허가를 받아 믿을 수 있는 사용자
authorized_keys 적용 과정
1. 앤서블 서버에서 앤서블 노드로 접속 시도
2. 앤서블 노드의 ~/.ssh/authorized_keys 파일의 존재 확인
3. authorized_keys 파일에 해당 호스트의 접속 허가 정보가 저장되어 있다면 접속 허용
autopass.yml 파일 수정
1) vars: 추가
2) ssh-keygen for authorized_keys file과 input key for each node 부분 추가
vars:
ansible_password: vagrant
- name: ssh-keygen for authorized_keys file
command: "ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ''"
ignore_errors: yes
run_once: true
- name: input key for each node
connection: ssh
authorized_key:
user: vagrant
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
코드 전체
---
- name: Create authority between server and nodes
hosts: nodes
connection: local
serial: 1
gather_facts: no
vars:
ansible_password: vagrant
tasks:
- name: ssh-keyscan for known_hosts file
command: /usr/bin/ssh-keyscan -t ecdsa {{ ansible_host }}
register: keyscan
- name: input key
lineinfile:
path: ~/.ssh/known_hosts
line: "{{ item }}"
create: yes
with_items:
- "{{ keyscan.stdout_lines }}"
- name: ssh-keygen for authorized_keys file
command: "ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ''"
ignore_errors: yes
run_once: true
- name: input key for each node
connection: ssh
authorized_key:
user: vagrant
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
vag_reconf.bat 파일 실행
PS C:\HashiCorp\udemy-ansible> .\vag_reconf.bat
-k 옵션과 암호 입력 없이 통신 확인 가능
ans nodes -m ping
728x90
'Ansible' 카테고리의 다른 글
220613_2_앤서블_심화_플레이북 동적 구성-when 조건 (0) | 2022.06.13 |
---|---|
220613_1_앤서블_심화_플레이북 동적 구성-FACT(s) (0) | 2022.06.13 |
220609_2_앤서블_심화_Known_hosts 자동 등록 (0) | 2022.06.10 |
220609_1_앤서블_심화_실습 환경 구성-vagrant (0) | 2022.06.09 |
220608_6_앤서블_응용_베이그런트를 이용한 우분투 가상 머신 생성 (0) | 2022.06.09 |