티스토리 뷰

카테고리 없음

ansible ansible all -m ping

미니대왕님 2023. 6. 7. 11:12
 

Ansible 설치 / 우분투 18.04 환경

ansible all -m ping

1. 설치 환경

[그림 1] Ansible 설치를 위한 Node 구성도

  • Ubuntu 18.04 LTS 64bit, root user

  • Ansible 2.9.27

2. Ansible 설치

apt-get install -y software-properties-common
apt-add-repository -y ppa:ansible/ansible
apt-get update -y
apt-get -y install ansible

3. Inventory 구성 (client ip 는 192.168.56.112 입니다.)

[cluster]
192.168.56.112

ansible-server :  /etc/ansible/hosts

 

4. SSH Key 생성 및 설정

$ssh-keygen -t rsa

root@ansibleserver:/etc/ansible# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:eolMO4/1GhHkvo9K5Ps2mtNn370m0qA+OPI7lWHdMDs root@ansibleserver
The key's randomart image is:
+---[RSA 2048]----+
|        .        |
|       o   o     |
|        o . =    |
|       . + E .   |
|      o S o .    |
|     = + * .     |
|      O.O . o    |
|     o.%+Bo. + o |
|      OOX*+.o +.o|
+----[SHA256]-----+

 

 Client 서버에 ansiblecli 라는 계정을 생성해봅니다. 패스워드도 설정합니다. 

root@ansibleclient:/home/vagrant# adduser ansiblecli
Adding user `ansiblecli' ...
Adding new group `ansiblecli' (1001) ...
Adding new user `ansiblecli' (1001) with group `ansiblecli' ...
Creating home directory `/home/ansiblecli' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for ansiblecli
Enter the new value, or press ENTER for the default
        Full Name []: 
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] y
root@ansibleclient:/home/vagrant#
root@ansibleserver:/etc/ansible# ssh-copy-id ansiblecli@192.168.56.112
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ansiblecli@192.168.56.112's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'ansiblecli@192.168.56.112'"
and check to make sure that only the key(s) you wanted were added.

5. Ansible 구동

 

6. 참조

댓글