월루를 꿈꾸는 대학생

Ansible 비번 없이 로그인 하는 yaml 파일 만들기 본문

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 }}"

 

 

해당 파일을 돌려주면 

처음에만 비번 입력하라고 하고 

 

그 뒤에 명령어 사용시에는 비번없이 가능 

 

 

 

참고

https://ossian.tistory.com/97

 

[Ansible] Authorized_keys 등록하기(SSH Key)

[Ansible] Authorized_keys 등록하기(SSH Key) Authorized Keys란? Ansible Server(Source)에서 Ansible Node(Destination) 접속 시도 시 계정에 대한 암호를 입력해야 합니다. 이러한 암호를 매번 입력하면 Ansi..

ossian.tistory.com

 

728x90

'Server&Network > Ansible' 카테고리의 다른 글

Ansible 계정 만들기  (0) 2020.12.25