토요일, 9월 14, 2024
HomeLinuxubuntu Ansible Install & setting

ubuntu Ansible Install & setting

ubuntu Ansible Install & setting

배포 자동화 도구인 Ansible 설치 및 간단한 테스트에 대한 메모입니다.

apt-get install software-properties-common

apt-get install software-properties-common

Reading package lists... Done
Building dependency tree       
Reading state information... Done
software-properties-common is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

apt-add-repository ppa:ansible/ansible

apt-add-repository ppa:ansible/ansible
 Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. 
 Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, 
 using SSH, with no agents to install on remote systems.

http://ansible.com/
 More info: https://launchpad.net/~ansible/+archive/ubuntu/ansible
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpkcl0tzgt/secring.gpg' created
gpg: keyring `/tmp/tmpkcl0tzgt/pubring.gpg' created
gpg: requesting key 7BB9C367 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpkcl0tzgt/trustdb.gpg: trustdb created
gpg: key 7BB9C367: public key "Launchpad PPA for Ansible, Inc." imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

apt-get update

apt-get update

apt-get install -y ansible

apt-get install -y ansible
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libyaml-0-2 python-crypto python-ecdsa python-httplib2 python-jinja2 python-markupsafe python-paramiko python-setuptools
  python-support python-yaml sshpass
Suggested packages:
  python-crypto-dbg python-crypto-doc python-jinja2-doc
The following NEW packages will be installed:
  ansible libyaml-0-2 python-crypto python-ecdsa python-httplib2 python-jinja2 python-markupsafe python-paramiko python-setuptools
  python-support python-yaml sshpass
0 upgraded, 12 newly installed, 0 to remove and 3 not upgraded.
Need to get 2,010 kB of archives.
After this operation, 12.4 MB of additional disk space will be used.
Get:1 http://kr.archive.ubuntu.com/ubuntu/ vivid/main libyaml-0-2 amd64 0.1.6-3 [47.6 kB]
Get:2 http://kr.archive.ubuntu.com/ubuntu/ vivid/universe python-support all 1.0.15 [26.7 kB]
Get:3 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-markupsafe amd64 0.23-1 [15.6 kB]
Get:4 http://ppa.launchpad.net/ansible/ansible/ubuntu/ vivid/main ansible all 2.0.1.0-1ppa~vivid [1,029 kB]
Get:5 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-jinja2 all 2.7.3-1 [161 kB]
Get:6 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-yaml amd64 3.11-2 [109 kB]
Get:7 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-crypto amd64 2.6.1-5 [240 kB]
Get:8 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-ecdsa all 0.11-1 [33.7 kB]                                                 
Get:9 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-paramiko all 1.15.1-1 [106 kB]                                             
Get:10 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-httplib2 all 0.9+dfsg-2 [34.3 kB]                                         
Get:11 http://kr.archive.ubuntu.com/ubuntu/ vivid/main python-setuptools all 12.2-1 [197 kB]                                            
Get:12 http://kr.archive.ubuntu.com/ubuntu/ vivid/universe sshpass amd64 1.05-1 [10.5 kB]                                               
Fetched 2,010 kB in 7s (279 kB/s)                                                                                                       
Selecting previously unselected package libyaml-0-2:amd64.
(Reading database ... 88700 files and directories currently installed.)
Preparing to unpack .../libyaml-0-2_0.1.6-3_amd64.deb ...
Unpacking libyaml-0-2:amd64 (0.1.6-3) ...
Selecting previously unselected package python-support.
Preparing to unpack .../python-support_1.0.15_all.deb ...
Unpacking python-support (1.0.15) ...
Selecting previously unselected package python-markupsafe.
Preparing to unpack .../python-markupsafe_0.23-1_amd64.deb ...
Unpacking python-markupsafe (0.23-1) ...
Selecting previously unselected package python-jinja2.
Preparing to unpack .../python-jinja2_2.7.3-1_all.deb ...
Unpacking python-jinja2 (2.7.3-1) ...
Selecting previously unselected package python-yaml.
Preparing to unpack .../python-yaml_3.11-2_amd64.deb ...
Unpacking python-yaml (3.11-2) ...
Selecting previously unselected package python-crypto.
Preparing to unpack .../python-crypto_2.6.1-5_amd64.deb ...
Unpacking python-crypto (2.6.1-5) ...
Selecting previously unselected package python-ecdsa.
Preparing to unpack .../python-ecdsa_0.11-1_all.deb ...
Unpacking python-ecdsa (0.11-1) ...
Selecting previously unselected package python-paramiko.
Preparing to unpack .../python-paramiko_1.15.1-1_all.deb ...
Unpacking python-paramiko (1.15.1-1) ...
Selecting previously unselected package python-httplib2.
Preparing to unpack .../python-httplib2_0.9+dfsg-2_all.deb ...
Unpacking python-httplib2 (0.9+dfsg-2) ...
Selecting previously unselected package python-setuptools.
Preparing to unpack .../python-setuptools_12.2-1_all.deb ...
Unpacking python-setuptools (12.2-1) ...
Selecting previously unselected package sshpass.
Preparing to unpack .../sshpass_1.05-1_amd64.deb ...
Unpacking sshpass (1.05-1) ...
Selecting previously unselected package ansible.
Preparing to unpack .../ansible_2.0.1.0-1ppa~vivid_all.deb ...
Unpacking ansible (2.0.1.0-1ppa~vivid) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libyaml-0-2:amd64 (0.1.6-3) ...
Setting up python-support (1.0.15) ...
Setting up python-markupsafe (0.23-1) ...
Setting up python-jinja2 (2.7.3-1) ...
Setting up python-yaml (3.11-2) ...
Setting up python-crypto (2.6.1-5) ...
Setting up python-ecdsa (0.11-1) ...
Setting up python-paramiko (1.15.1-1) ...
Setting up python-httplib2 (0.9+dfsg-2) ...
Setting up python-setuptools (12.2-1) ...
Setting up sshpass (1.05-1) ...
Setting up ansible (2.0.1.0-1ppa~vivid) ...
Processing triggers for libc-bin (2.21-0ubuntu4) ...
Processing triggers for python-support (1.0.15) ...

ssh-keygen

ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
c4:d5:09:81:d3:d2:5a:51:da:1b:98:b9:30:0e:a2:3a user@ansible
The key's randomart image is:
+---[RSA 2048]----+
|         +=*..   |
|       .+.+*o    |
|    . . === o    |
|   . . +.o . o   |
|  .     S . .    |
| .               |
|E                |
| .               |
|                 |
+-----------------+

일반 계정사용시 sudo nopasswd 부여하기

echo '계정명 ALL=(ALL) NOPASSWD:ALL'>> /etc/sudoers

내용을 복사후 접속할 타서버의 .ssh/authorized_keys 에 붙여놓기합니다.
cat .ssh/isa.pub

cat .ssh/isa.pub

접속확인
ssh 172.16.16.103

ssh 172.16.16.103

작업을 수행할 서버들에 대한 정보를 저장
cat /etc/ansible/hosts

cat /etc/ansible/hosts 
[group_name]
alias ansible_ssh_host=172.16.16.102

[hosts]
proxy ansible_ssh_host=172.16.16.103
tomcat ansible_ssh_host=172.16.16.104
django ansible_ssh_host=172.16.16.105

관련 폴더생성

mkdir /etc/ansible/group_vars
nano /etc/ansible/group_vars/hosts
ansible_ssh_user: root

hosts 그룹에 속한 서버들에 대한 ping 테스트
ansible -m ping hosts

ansible -m ping hosts
proxy | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
tomcat | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
django | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

한대(proxy)의 서버에 대해서 ping 테스트
ansible -m ping proxy

ansible -m ping proxy
proxy | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

두대(proxy,django)의 서버에 대해서 ping 테스트
ansible -m ping proxy:django

ansible -m ping proxy:django
django | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
proxy | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

proxy 서버에 대한 shell 실행
ansible -m shell -a ‘df -h’ proxy

ansible -m shell -a 'df -h' proxy
proxy | SUCCESS | rc=0 >>
Filesystem                   Size  Used Avail Use% Mounted on
udev                         486M     0  486M   0% /dev
tmpfs                        100M  8.8M   91M   9% /run
/dev/mapper/django--vg-root   15G  2.1G   12G  16% /
tmpfs                        497M     0  497M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                        497M     0  497M   0% /sys/fs/cgroup
/dev/sda1                    236M   74M  150M  33% /boot
tmpfs                        100M     0  100M   0% /run/user/1000
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular