오늘은 배운 개념을 가지고 실제 서버를 GCP로 만들고 Ansible 서버에서

다른 서버인 로키, 우분투 서버에 여러 동작을 시켜보는 실습이다.

 

Ansible 사용하기

먼저 실습환경은 GCP에서 진행

새로운 VM을 만들고 아래의 명령어 실행

--- Ansible 서버 설치
$ sudo dnf install epel-release -y
$ sudo dnf --enablerepo=epel -y install ansible
$ ansible --version
### Ansible 문서 사이트 <https://docs.ansible.com/ansible/latest/index.html>

이제 Ansible이 명령을 실행할 대상 서버들의 IP와 그룹을 지정하는 파일을 설정해줘야한다.

--- Ansible의 CLI
# sudo vi /etc/ansible/hosts
[rocky]
10.178.0.5

[ubuntu]
10.178.0.3

이게 인벤토리에 등록해주는 것이다.

이 인벤토리 별로 playbook을 나눠 적용할 수 있다.

모듈이란?

Ansible에서 뭘할지 결정하는 기능 단위 명령어이다.

 

자주 쓰는 모듈

모듈 이름 하는 일
ping 대상 서버와 연결 확인 (Python 실행 가능 여부)
command 일반 명령어 실행 (셸 아님)
shell 셸 명령어 실행 (리다이렉션, 파이프 등 가능)
copy 파일 복사
file 파일/디렉토리 권한 설정, 생성, 삭제
yum, apt 패키지 설치/삭제
service 서비스 시작/중지/재시작
ansible all -m ping
ERROR: Ansible could not initialize the preferred locale: unsupported locale setting
ansible --version
ERROR: Ansible could not initialize the preferred locale: unsupported locale setting
이건 locale 설정이 UTF-8로 되어있지 않아 발생한 애러

이렇게 locale을 변경해주면 됨 이건 시스템 전체에 적용하는거
sudo localectl set-locale LANG=en_US.UTF-8

locale 변경 후에도 아래와 같은 에러 발생

[park@ansible ~]$ ansible all -m ping
The authenticity of host '10.178.0.5 (10.178.0.5)' can't be established.
ECDSA key fingerprint is SHA256:Lws5dEDAtEdsY6y6Zqa7wZDYMTfcn0frENHj19ifEls.
The authenticity of host '10.178.0.3 (10.178.0.3)' can't be established.
ECDSA key fingerprint is SHA256:6yx3tMCPCg+hJqWyYBV4olngOP3FsgshL9kUR0PtBkQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])?  yes
10.178.0.5 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Warning: Permanently added '10.178.0.5' (ECDSA) to the list of known hosts.\\r\\npark@10.178.0.5: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).",
    "unreachable": true
}
ㄴ yes
10.178.0.3 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Warning: Permanently added '10.178.0.3' (ECDSA) to the list of known hosts.\\r\\nConnection closed by 10.178.0.3 port 22",
    "unreachable": true
}

이건 ansible 에서 내 로키나 우분투 VM에 SSH 접근하는 것임

근데 여기에는 키인증 방식을 사용하지 않고 그냥 접근하려고 해서 접근거부 당한 것

 

1. 나를 대신할 ansible에 키를 넣기

 

2. /etc/ansible/hosts 수정

[rocky]
10.178.0.5 ansible_user=park ansible_ssh_private_key_file=mykey

[ubuntu]
10.178.0.3 ansible_user=park ansible_ssh_private_key_file=mykey

 

3. 다시시도

[park@ansible ~]$ ansible all -m ping
10.178.0.5 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
10.178.0.3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

  • /etc/ansible/hosts → 전체 인벤토리 파일(기본 인벤토리 파일임)
  • [rocky] → 그 안의 그룹
  • 10.178.0.5, 10.178.0.6 → rocky 그룹에 속한 실제 호스트들

~/.ssh/known_hosts 서버 접속마다 물어보는 fingerprint: yes or no

많은 걸 자동화하기 위해 쓰는건데 VM 수 만큼 yes를 누르는건 용납 X

# 먼저 기존에 있던거 삭제
rm -rf ~/.ssh/known_hosts
# 호스트를 수동으로 등록해 새로이 접속할 경우도 미리 작상되어 있어 뭍지 않음
ansible localhost -m known_hosts -a "path=~/.ssh/known_hosts name=10.178.0.5 key='$(ssh-keyscan -t rsa 10.178.0.5)' state=present"

# 입력 자동화를 위해 사용
$ for host in 10.178.0.3 10.178.0.5; do
  ansible localhost -m known_hosts -a "path=~/.ssh/known_hosts name=$host key='$(ssh-keyscan -H $host 2>/dev/null)' state=present"
done

localhost | CHANGED => {
    "changed": true,
    "gid": 1001,
    "group": "park",
    "hash_host": false,
    "key": "|1|vneNPpYBguupSlzdHAgl",
    "mode": "0664",
    "name": "10.178.0.3",
    "owner": "park",
    "path": "/home/park/.ssh/known_hosts",
    "secontext": "unconfined_u:object_r:ssh_home_t:s0",
    "size": 978,
    "state": "file",
    "uid": 1000
}

  • ansible localhost(내 호스트 VM에서 진행하겠다.)
  • -m known_hosts(Ansible의 known_hosts 모듈사용)
  • -a "path=~/.ssh/known_hosts name=$host key='$(ssh-keyscan -H $host 2>/dev/null)' state=present"
    • SSH 호스트 키를 저장할 파일 경로
    • 보통 사용자의 known_hosts 파일은 ~/.ssh/known_hosts야
    • 이 파일에 특정 호스트(IP)의 SSH 공개키를 저장하는 거지

    name=$host
    • 대상 호스트 이름 또는 IP 주소
    • 예: 10.178.0.12, 10.178.0.13
    • known_hosts 파일에서 이 이름으로 키를 매핑함
    즉, "10.178.0.12라는 서버의 키를 저장해줘"라는 의미
    key='$(ssh-keyscan -H $host 2>/dev/null)'
    • ssh-keyscan은 해당 호스트의 SSH 공개 호스트 키를 가져오는 명령어
  • path=~/.ssh/known_hosts

이렇게 변경이 되고 fingerprint를 뭍지 않고 바로 ping 가능

[park@ansible ~]$ ansible all -m ping --private-key mykey
10.178.0.5 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
10.178.0.3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}
sudo vi /etc/ansible/ansible.cfg
여기에 내 키를 작성하면 
$ ansible all -m ping --private-key mykey 이렇게 키를 일일이 안 넣어줘도 가능함

# 커스텀 인벤토리 만들기
all 을 사용할때도 전부다가 아닌 내가 지정한 것들만 나오게 할수도 있음 inventory.list로
$ echo "10.178.0.3" >> inventory.list
$ echo "10.178.0.5" >> inventory.list
[park@ansible ~]$ ansible all -i inventory.list -m ping
10.178.0.5 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
10.178.0.3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

ad-hoc 방식

# 임시 ad-hoc
$ansible 10.178.0.5 -i inventory.list -m ping
이렇게 인벤토리에 없지만 있는 것처럼
# 완전 ad-hoc
ansible 10.178.0.5 -i "10.178.0.5," -m ping

uptime 확인

[park@ansible ~]$ ansible all -m shell -a "uptime"
10.178.0.3 | CHANGED | rc=0 >>
 06:11:26 up  3:30,  1 user,  load average: 0.00, 0.00, 0.00
10.178.0.5 | CHANGED | rc=0 >>
 06:11:26 up  3:30,  2 users,  load average: 0.06, 0.02, 0.00

만약 인벤토리가 웹서버라면 다운 된적이 있다면 업타임이 다를 수 있다.

df -h 확인

디스크 용량 확인 -h MB, GB로 출력

[park@ansible ~]$ ansible all -m shell -a "df -h"
10.178.0.5 | CHANGED | rc=0 >>
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           1.8G     0  1.8G   0% /dev/shm
tmpfs           1.8G  8.4M  1.8G   1% /run
tmpfs           1.8G     0  1.8G   0% /sys/fs/cgroup
/dev/sda2        20G  4.5G   16G  23% /
/dev/sda1       200M  5.8M  194M   3% /boot/efi
tmpfs           367M     0  367M   0% /run/user/1000
10.178.0.3 | CHANGED | rc=0 >>
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       8.7G  1.6G  7.1G  19% /
tmpfs           983M     0  983M   0% /dev/shm
tmpfs           393M  660K  393M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
efivarfs         56K   24K   27K  48% /sys/firmware/efi/efivars
/dev/sda16      881M   47M  772M   6% /boot
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           197M  8.0K  197M   1% /run/user/1001

free -h 확인

메인 메모리 용량을 확인하는 것

[park@ansible ~]$ ansible all -m shell -a "free -h"
10.178.0.5 | CHANGED | rc=0 >>
              total        used        free      shared  buff/cache   available
Mem:          3.6Gi       231Mi       2.8Gi       8.0Mi       609Mi       3.1Gi
Swap:            0B          0B          0B
10.178.0.3 | CHANGED | rc=0 >>
               total        used        free      shared  buff/cache   available
Mem:           1.9Gi       309Mi       1.5Gi       668Ki       319Mi       1.6Gi
Swap:             0B          0B          0B

시간대 조정하기

[park@ansible ~]$ ansible all -m shell -a "timedatectl set-timezone Asia/Seoul" -b
10.178.0.5 | CHANGED | rc=0 >>
10.178.0.3 | CHANGED | rc=0 >>

-b 를 사용해 become 루트 권한을 사용할 수 있다.

여기서 결과에서는 CHANGED라는 단어가 계속 들어감 이게 shell 이라는 모듈의 특징

shell 모듈은 리눅스 명령어를 인벤토리 호스트들에게 명령어를 실행해주는건데 이건 부하를 줄 수 있음

멱등성이 없는 것

멱등성 보장 시간대 조정하기

[park@ansible ~]$ ansible all -m timezone -a "name=Asia/Seoul"
10.178.0.5 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false
}
10.178.0.3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false
}

-m shell을 사용하는게 아닌 별도의 모듈을 사용하면 멱등성을 얻을 수 있다.

변경이 필요한 경우는 당연하게 CHANGED가 붙음

[park@ansible ~]$ ansible all -m timezone -a "name=Asia/Tokyo" -b
10.178.0.5 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "executed `/bin/timedatectl set-timezone Asia/Tokyo`"
}
10.178.0.3 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": true,
    "msg": "executed `/usr/bin/timedatectl set-timezone Asia/Tokyo`"
}

[park@ansible ~]$ ansible all -m timezone -a "name=Asia/Tokyo" -b
10.178.0.5 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false
}
10.178.0.3 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false
}

여기서 만약 -b 를 매번 치는게 힘들다면 아래와 같이 추가하면 된다.

[park@ansible ~]$ sudo vi /etc/ansible/ansible.cfg
[privilege_escalation]
become=True

사용자 추가

# -m shell "adduser kosa" 와 같은거
[park@ansible ~]$ ansible all -m user -a "name=kosa state=present" -b
10.178.0.5 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "comment": "",
    "create_home": true,
    "group": 1003,
    "home": "/home/kosa",
    "name": "kosa",
    "shell": "/bin/bash",
    "state": "present",
    "system": false,
    "uid": 1002
}
10.178.0.3 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": true,
    "comment": "",
    "create_home": true,
    "group": 1003,
    "home": "/home/kosa",
    "name": "kosa",
    "shell": "/bin/sh",
    "state": "present",
    "system": false,
    "uid": 1002
}

사용자 추가 확인

[park@ansible ~]$ ansible all -m shell -a "tail -n 1 /etc/passwd"
10.178.0.5 | CHANGED | rc=0 >>
kosa:x:1002:1003::/home/kosa:/bin/bash
10.178.0.3 | CHANGED | rc=0 >>
kosa:x:1002:1003::/home/kosa:/bin/sh

사용자 비밀번호 적용

# 비밀번호 암호화
[park@ansible ~]$ openssl passwd -6 'Test1752!'
$6$SCNbUKok2ORIlt4N$QUI1dO6/.Y36SJN6Pg4r63IZquCE5Bsed95XOhli4svqqSvL6VJIpPwbQGjDqvrtuzeUckjfKuLXFP0Rg3nro.
$표시에는 \\를 넣어줘야함
\\$6\\$SCNbUKok2ORIlt4N\\$QUI1dO6/.Y36SJN6Pg4r63IZquCE5Bsed95XOhli4svqqSvL6VJIpPwbQGjDqvrtuzeUckjfKuLXFP0Rg3nro.

ansible all -m user -a "name=kosa password='\\$6\\$SCNbUKok2ORIlt4N\\$QUI1dO6/.Y36SJN6Pg4r63IZquCE5Bsed95XOhli4svqqSvL6VJIpPwbQGjDqvrtuzeUckjfKuLXFP0Rg3nro.' state=present"

 

하지만 이렇게 비밀번호를 만들어줘도 해당 서버의 ssh 설정에서 PasswordAuthentication을 허용 안할 수 있다. 이걸 바꿔줄 필요가 있다.

접속할 서버 SSH 비밀번호 접속 허용

host 서버 접속 → vi /etc/ssh/sshd_config → PasswordAuthentication yes

[park@ansible ~]$ ssh kosa@10.178.0.5
kosa@10.178.0.5's password:

# 삭제
$ ansible all -m user -a "name=kosa state=absent"

패키지 설치하기

VM에 묶어서 패키지 설치가 가능하다

[park@ansible ~]$ ansible rocky -m dnf -a "name=httpd state=present" -b
10.178.0.5 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: httpd-2.4.37-65.module+el8.10.0+1984+1bed3124.4.x86_64",
        "Installed: httpd-tools-2.4.37-65.module+el8.10.0+1984+1bed3124.4.x86_64",
        "Installed: mod_http2-1.15.7-10.module+el8.10.0+1938+3b7755d4.3.x86_64",
        "Installed: rocky-logos-httpd-86.3-1.el8.noarch",
        "Installed: apr-1.6.3-12.el8.x86_64",
        "Installed: httpd-filesystem-2.4.37-65.module+el8.10.0+1984+1bed3124.4.noarch",
        "Installed: mailcap-2.1.48-3.el8.noarch",
        "Installed: apr-util-1.6.1-9.el8.x86_64",
        "Installed: apr-util-bdb-1.6.1-9.el8.x86_64",
        "Installed: apr-util-openssl-1.6.1-9.el8.x86_64"
    ]
}

아파치 명령어 정리

$ ansible rocky -m service -a "name=httpd state=started"
$ ansible rocky -m shell -a "systemctl status httpd"
$ ansible rocky -m service -a "name=httpd state=stopped"
$ ansible rocky -m dnf -a "name=httpd state=absent"

해당 VM 들어가지도 않고 웹서버 띄우고 접속도 함

 

 

Ubuntu Apache2

$ ansible ubuntu -m apt -a "update_cache=yes"
$ ansible ubuntu -m apt -a "name=apache2 state=present"
$ ansible ubuntu -m service -a "name=apache2 state=stopped"
$ ansible ubuntu -m service -a "name=apache2 state=started"
$ ansible ubuntu -m apt -a "name=apache2 state=absent"

 

 

배포 명령어 관리

--- 배포 명령어 관리
[park@ansible ~]$ ls
food.tar  hostlist.txt  inventory.list
[park@ansible temp]$ tar xvf food.tar
[park@ansible temp]$ ansible all -m copy -a "src=index.html dest=/var/www/html/index.html"
[park@ansible temp]$ ansible all -m copy -a "src=assets/ dest=/var/www/html/assets/"
[park@ansible temp]$ ansible all -m copy -a "src=vendors/ dest=/var/www/html/vendors"

// 원격 서버가 인터넷에 나갈 때 사용하는 공인 IP 주소 확인
[park@ansible temp]$ ansible all -m shell -a "curl ifconfig.io"
10.178.0.5 | CHANGED | rc=0 >>
35.216.107.136  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    15  100    15    0     0     64      0 --:--:-- --:--:-- --:--:--    64
10.178.0.3 | CHANGED | rc=0 >>
35.216.41.111  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    14  100    14    0     0     58      0 --:--:-- --:--:-- --:--:--    58

# 한번에 하는 건 
$ ansible all -m unarchive -a "src=./aws.tar dest=/var/www/html/"

우분투

 

로키

 

파일에 문장 추가하기

-m lineinfile 이 모듈로 처리

# echo "172.16.0.100" >> inventory.list
# cat inventory.list
# echo "172.16.0.100" >> inventory.list
# cat inventory.list

# 멱등성 없음
[park@ansible ~]$ echo "172.16.0.100" >> inventory1.list
[park@ansible ~]$ echo "172.16.0.100" >> inventory1.list
[park@ansible ~]$ cat inventory1.list
172.16.0.100
172.16.0.100

# 멱등성 있음
[park@ansible ~]$ ansible localhost -c local -m lineinfile -a "path=inventory1.list line=172.16.0.200"
localhost | CHANGED => {
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[park@ansible ~]$ ansible localhost -c local -m lineinfile -a "path=inventory1.list line=172.16.0.200"
localhost | SUCCESS => {
    "backup": "",
    "changed": false,
    "msg": ""
}
[park@ansible ~]$ cat inventory1.list
172.16.0.100
172.16.0.100
172.16.0.200

-c 는 ssh 사용하지 않겠다 왜? localhost 안에서 작동하니까

즉 lineinfile로 추가한다면 동일한걸 추가하려하면 추가되지 않는다.

이로써 여러번 시도해도 결과가 같은 멱등성이 보장된다.

서버가 많으니 중복 요청이 많을 수 있기에 멱등성이 중요하다.

Playbook

hosts 처럼 인벤토리에 여러 OS나 기능 별로 그룹을 나눴으면,

이제 그 각각에 맞춰서 어떤걸 수행시킬지 작성해야한다.

플레이북 구조

YAML 형식으로 작성된 각각의 Playbook들은 하나 이상의 Play를 가지며, 각각의 Play는 하나 이상의 task(Ansible 모듈)을 실행한다

rocky, ubuntu 아파치 설치 플레이북 만들기

$ mkdir ansible && cd $_
$ vi apache_install.yml
- name: Deploy Apache and content on Rocky
  hosts: rocky

  tasks:
    - name: Install Apache web server
      dnf:
        name: httpd
        state: present

    - name: Upload default index.html for web server
      copy:
        src: ~/index.html  # 로컬 경로를 설정하세요
        dest: /var/www/html/index.html
        mode: "0644"
    - name: Create images directory if not exists
      file:
        path: /var/www/html/images
        state: directory
        mode: "0755"

    - name: Upload image to the web server
      copy:
        src: ~/images/two-rabbit.jpg  # 로컬 경로를 설정하세요
        dest: /var/www/html/images/two-rabbit.jpg
        mode: "0644"

    - name: Start Apache web server
      service:
        name: httpd
        state: started
        enabled: yes

- name: Install apache on ubuntu
  hosts: ubuntu
  tasks:
    - name: Install apache web server
      apt:
        name: apache2
        state: present

    - name: Upload custom index.html to the web server
      copy:
        src: ~/index.html
        dest: /var/www/html/index.html
        mode: "0644"

    - name: Create images directory if it does not exist
      file:
        path: /var/www/html/images
        state: directory
        mode: "0755"

    - name: Upload image to the web server
      copy:
        src: ~/images/two-rabbit.jpg
        dest: /var/www/html/images/two-rabbit.jpg
        mode: "0644"

    - name: Start apache web server
      service:
        name: apache2
        state: started
        enabled: yes

하나의 플레이에 여러 개의 테스크가 들어감

이건 단지 앞서 했던 명령어를 yaml 파일로 만든것이다.

Dockerfile 같은 개념

테스트 1

  • HTTPD 설치하기
  • dnf: name: httpd state: present
  • index.html 옮기기
  • src: ~/index.html # 로컬 경로를 설정하세요 dest: /var/www/html/index.html mode: "0644"
  • httpd 시작하기
  • service: name: httpd state: started enabled: yes

apache 삭제

[park@ansible ansible]$ ansible rocky -m dnf -a "name=httpd state=absent"
10.178.0.5 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Removed: mod_http2-1.15.7-10.module+el8.10.0+1938+3b7755d4.3.x86_64",
        "Removed: httpd-2.4.37-65.module+el8.10.0+1984+1bed3124.4.x86_64"
    ]
}
[park@ansible ansible]$ ansible ubuntu -m apt -a "name=apache2 state=absent"
10.178.0.3 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": true,
    "stderr": "",
    "stderr_lines": [],
    "stdout": "Reading package lists...\\nBuilding dependency tree...\\nReading state information...\\nThe following packages were automatically installed and are no longer required:\\n  apache2-bin apache2-dat

playbook 써보기

[park@ansible ansible]$ ansible-playbook apache_install.yml

PLAY [Deploy Apache and content on Rocky] ************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************
ok: [10.178.0.5]

TASK [Install Apache web server] *********************************************************************************************
ok: [10.178.0.5]

TASK [Upload default index.html for web server] ******************************************************************************
changed: [10.178.0.5]

TASK [Create images directory if not exists] *********************************************************************************
changed: [10.178.0.5]

TASK [Upload image to the web server] ****************************************************************************************
changed: [10.178.0.5]

TASK [Start Apache web server] ***********************************************************************************************
changed: [10.178.0.5]

PLAY [Install apache on ubuntu] **********************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************
ok: [10.178.0.3]

TASK [Install apache web server] *********************************************************************************************
changed: [10.178.0.3]

TASK [Upload custom index.html to the web server] ****************************************************************************
changed: [10.178.0.3]

TASK [Create images directory if it does not exist] **************************************************************************
changed: [10.178.0.3]

TASK [Upload image to the web server] ****************************************************************************************
changed: [10.178.0.3]

TASK [Start apache web server] ***********************************************************************************************
ok: [10.178.0.3]

PLAY RECAP *******************************************************************************************************************
10.178.0.3                 :ok=6changed=4 unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
10.178.0.5                 :ok=6changed=4 unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 

마무리

다양한 모듈을 통해 인벤토리에 있는 그룹/호스트 에게 여러 명령을 할 수 있었고

모듈로 주는 명령은 멱등성이 있는지 잘 체크해서 사용해야한다.

오늘 한 건 간단한 웹서버를 띄우고 내리고 하는 작업이었다.

이 간단한 작업도 서버 안으로 SSH로 들어가서 명령어를 일일이 쳤어야 했는데 그냥 yml 파일 하나를 실행시키는 것 만으로 이렇게 생성하고 삭제하는 작업을 여러 노드에 한 번에 할 수 있는 매우 편리한 기능 같다.

+ Recent posts