• 이미 사용 허가를 받아서 믿을 수 있는 사용자

1. ansible에서 authorized_keys 저장하는 순서

  1. ansible 서버에서 ansible 클라이언트에 접속 시도
  2. ansible 클라이언트는 ~/.ssh/authorized_keys 파일의 존재 확인
  3. authorized_keys 파일 내용에 ansible 서버의 정보가 저장되어있는 지 확인하고, 있다면 접속을 허가

2. ssh-keygen 명령어 사용

  • ssh-keygen 명령어를 통해 생성된 공개키(.pub)를 ansible 클라이언트에 전달하여 암호없이 접근 가능하게 해줌
  • authorized_keys에 저장하는 데 사용하는 명령어 ssh-keygen 옵션 설명
    1. -b 옵션 : 생성할 키의 비트수를 지정
    2. 2048 : rsa 키는 2048 비트로 결정 (rsa는 최소 768 비트가 필요)
    3. -t 옵션 : 암호화 타입을 결정
    4. rsa : 공개키 암호화에서 가장 널리 사용되는 알고리즘
    5. -f ~/.ssh/id_rsa : 저장할 파일명 지정
    6. -q 옵션 : ssh-keygen의 질의 응답을 생략
    7. -N "" : 새 암호를 빈값으로 해서 제공
       $ ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""

3. 자동으로 authorized_keys를 저장해주는 플레이북(playbook)

  1. hosts: all → /etc/ansible/hosts에 저장되어있는 모든 IP 호스트들을 대상

  2. gather_facts: no → facts를 수집하지 않는다는 것 → Facts 는 원격 대상 시스템의 호스트 네임, CPU, Memory 정보 등을 수집하는 setup 모듈 (불필요한 시간 소모를 막아줌)

  3. connection=local → Ansible 이 ssh로 명령어를 날리지 않도록 하기 위한 것

  4. ignore_errors: yes → ansible 스크립트에서 실행한 결과가 성공인지 실패인지 출력하지 않고 실행만 시킴

  5. run_once: true → 명령어 1회만 실행됨

  6. register: id_pub → 플레이북에서의 결과를 id_pub 변수로 지정

  7. lineinfile → 이미 존재하는 파일에 내가 추가할 라인이 있는지 체크하고, 없는 경우에만 추가하고 싶은 경우에 lineinfile module을 사용 (ansible의 멱등성 지원)

  8. dest → id_pub가 저장되는 위치인 /root/.ssh/authorized_keys임

  9. id_pub.stdout → /root/.ssh/authorized_keys에 id_rsa.pub을 저장

    $ vi auto_authorized_keys.yml
    ---
    - hosts: all
     gather_facts: no
    
     tasks:
     - name: ssh-keygen
       connection: local
       command: "ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ''"
       ignore_errors: yes
       run_once: true
    
     - name: read id_rsa.pub
       connection: local
       command: "cat ~/.ssh/id_rsa.pub"
       register: id_pub
       run_once: true
    
     - name: remote lineinfile for authorized_keys
       lineinfile:
         dest: /root/.ssh/authorized_keys
         line: "{{ id_pub.stdout }}"

4. 플래이북 실행 결과

  • ansible 서버에서 플레이북 실행

    $ ansible-playbook auto_authorized_keys.yml -k
    SSH password:
    
    PLAY [all] *******************************************************************
    
    TASK [ssh-keygen] ************************************************************
    changed: [192.168.1.13]
    
    TASK [read id_rsa.pub] *********************************************************
    changed: [192.168.1.13]
    
    TASK [remote lineinfile for authorized_keys] ****************************************
    changed: [192.168.1.13]
    
    PLAY RECAP *******************************************************************
    192.168.1.13             : ok=3    changed=3    unreachable=0    failed=0    skipped=0    rescued=0                                                                                                ignored=0
    
    # -k 옵션 없이 ansible 서버에서 ansible 클라이언트 ansible 명령어 실행
    $ ansible all -m ping
    192.168.1.13 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": false,
        "ping": "pong"
    }
  • ansible 클라이언트인 192.168.1.13에서 /root/.ssh/authorized_keys 파일 확인
    $ cat /root/.ssh/ssh
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuIvAkdFC/ltBW3j1oMIzoVAvo0Gr0rWPuZ8e+YdMnXd3YMCZ0DTrqd+B9TW/C56rCU7oD7thMb4JgZiLoUim87xYmVStSmacCGLEpfU6vcLJN/s4iu+oH0aSf/rWCDqElGun8kU5SdyILFLG8dtR/hHy7mvZjmE5Fm9OzuXIo+6wWeXx7I7UHUwL4b1FXaQwlw72IjLMC0BEcJCqxbnw+N9GWtzxkPMog++8EQ0JrLsnhGPNGoH8viI6jzitJwDQsxFenHEmoMZPTZxr4z2Yzct45GiTa5BRIpiqx3Oq/2wFuqC67oJIMOl+v/0xxa4UXv1qmL42KaSlUbtzz2wHj

ansible의 플레이북(playbook)

  • 플레이북(playbook)의 원래 뜻은 각본, 작전, 계획
  • ansible에서 플레이북(playbook)은 대량의 서버에 설치 및 실행할 때의 순서를 정의
  • ansible 플레이북을 이용하여 대량의 서버에 nginx 설치하고 실행하는 순서
    1. nginx 설치
    2. 파일 전송
    3. nginx 재시작

1. ansible에서 멱등성

  • 연산을 여러 번 적용하다라도 결과가 달라지지 않는 성질

  • 멱등성이 없는 경우(단순 명령어)

    # 아래 명령어를 계속 반복하면 /etc/ansible/hosts 아래에 같은 구문이 계속 생김
    # 아래 명령어 실행할 때 마다 추가됨
    echo -e "[playbook]\\n192.168.1.13" >> /etc/ansible/hosts
  • 멱등성이 있는 경우 (playbook이용)

    $ vi playbook.yml
    ---
    - name: Ansible_vim
      host: localhost
    
      tasks:
        - name: Add ansible hosts
          blockinfile:
            path: /etc/ansible/hosts
            block: |
              [playbook]
              192.168.1.13

2. ansible에서 YAML

  • YAML은 마크업 언어가 아님을 표방해서 나왔지만 마크업 언어로 사용됨

  • 사용자가 쉽게 작성하고 이해할 수 있도록 작성

  • XML을 넘어 JSON과 유사 혹은 거의 동일

  • YAML 파일에 대한 설명

    1. name : 실행하는 playbook의 이름

    2. host : 실행되는 장소

    3. tasks : 실행할 작업들

    4. name : 작업에 대한 이름

    5. blockinfile : 모듈의 이름으로 특정 블록을 파일에 기록하는 역할을 함

    6. path : 저장되는 파일의 이름

    7. block : block을 기록하는 시작 포인터를 | 으로 사용

    8. 끝은 지정하지 않았으면 내용은 [playbook]\n192.168.1.13으로 기록

      $ vi playbook.yml
      ---
      - name: Ansible_vim
      host: localhost
      
      tasks:
        - name: Add ansible hosts
          blockinfile:
            path: /etc/ansible/hosts
            block: |
              [playbook]
              192.168.1.13



플레이북(playbook)을 이용하여 nginx 설치 및 실행

  • ansible 서버에 플레이북을 정의하여 ansible 클라이언트에 nginx 설치 및 실행을 시킴

1. nginx 설치하여 실행할 YAML 파일 생성

$ vi install_nginx.yml
---
- hosts: all
  remote_user: root
  tasks:
    - name: install epel-release
      yum: name=epel-release state=latest
    - name: install nginx web server
      yum: name=nginx state=present
    - name: Upload basic index.html for web server
      copy: src=index.html dest=/usr/share/nginx/html/ mode=0644
    - name: start nginx web server
      service: name=nginx state=started

2. ansible 서버에 nginx 기본 시작 페이지를 다운받음

  • 각 ansible 클라이언트의 기본 시작 페이지를 지정

    $ curl -o index.html <https://www.nginx.com>
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 97615    0 97615    0     0  31715      0 --:--:--  0:00:03 --:--:-- 31724
    
    $ ls
    index.html

3. 플레이북 실행

$ ansible-playbook install_nginx.yml -k
SSH password:

PLAY [all] *************************************************************************

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

TASK [install epel-release] *************************************************************
ok: [192.168.1.13]

TASK [install nginx web server] **********************************************************
changed: [192.168.1.13]

TASK [start nginx web server] ********************************************************
changed: [192.168.1.13]

PLAY RECAP ************************************************************************
192.168.1.13             : ok=5    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

4. ansible 클라이언트인 192.168.1.13에서 실행 결과 확인


  • 한번의 명령어로 다수의 시스템에 작업

1. uptime 확인

  • all : ansible 클라이언트의 모든 노드를 대상
  • -m 옵션 : 사용할 모듈을 지정하기 위한 옵션
  • shell : -m 옵션의 값으로 shell을 지정하면 shell 명령어를 사용 가능
  • -a 옵션 : argument의 약어 shell에서 사용할 명령어를 지정하는 옵션
  • "uptime" : -a 옵션의 값으로 모든 ansible 클라이언트에게 uptime 명령어를 실행하게 함
  • -k 옵션 : SSH 접속을 위한 암호 입력을 가능하게 함
    $ ansible all -m shell -a "uptime" -k
    SSH password:
    8.8.8.8 | CHANGED | rc=0 >>
     00:41:11 up 58 days, 36 min,  1 user,  load average: 0.00, 0.01, 0.05

2. 디스크 용량 확인

  • all : ansible 클라이언트의 모든 노드를 대상
  • -m 옵션 : 사용할 모듈을 지정하기 위한 옵션
  • shell : -m 옵션의 값으로 shell을 지정하면 shell 명령어를 사용 가능
  • -a 옵션 : argument의 약어 shell에서 사용할 명령어를 지정하는 옵션
  • "df -h" : -a 옵션의 값으로 모든 ansible 클라이언트에게 df -h명령어를 실행하게 함 → df 명령어에 -h 옵션을 붙이려면 ""(큰 따옴표)를 사용해야 함
    # 이미 ssh 접속에 성공했기 때문에 -k 옵션 사용 X
    $ ansible all -m shell -a "df -h"
    8.8.8.8 | CHANGED | rc=0 >>
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs         63G     0   63G   0% /dev
    tmpfs            63G  4.0K   63G   1% /dev/shm
    tmpfs            63G  163M   63G   1% /run
    tmpfs            63G     0   63G   0% /sys/fs/cgroup
    /dev/sda2       243G  9.4G  221G   5% /
    /dev/sda1       477M  149M  299M  34% /boot
    /dev/sdb1       1.5T   77M  1.4T   1% /cache1
    tmpfs            13G     0   13G   0% /run/user/0

3. 메모리 상태 확인

  • all : ansible 클라이언트의 모든 노드를 대상
  • -m 옵션 : 사용할 모듈을 지정하기 위한 옵션
  • shell : -m 옵션의 값으로 shell을 지정하면 shell 명령어를 사용 가능
  • -a 옵션 : argument의 약어 shell에서 사용할 명령어를 지정하는 옵션
  • "free -h" : -a 옵션의 값으로 모든 ansible 클라이언트에게 free -h명령어를 실행하게 함 → free 명령어에 -h 옵션을 붙이려면 ""(큰 따옴표)를 사용해야 함
    $ ansible all -m shell -a "free -h"
    8.8.8.8 | CHANGED | rc=0 >>
                  total        used        free      shared  buff/cache   available
    Mem:           125G        5.2G        110G        162M        9.6G        119G
    Swap:           31G          0B         31G

4. 새로운 유저 생성

  • all : ansible 클라이언트의 모든 노드를 대상
  • -m 옵션 : 사용할 모듈을 지정하기 위한 옵션
  • user : -m 옵션의 값으로 user을 지정하면 linux의 user 생성
  • -a 옵션 : argument의 약어로 id와 password를 지정
  • "name=hippo password=1234" : 생성되는 user의 이름을 hippo로 하고, 비밀번호를 1234로 함 → ""(큰 따옴표)를 사용해야 id와 password를 같이 지정 가능
    $ ansible all -m user -a "name=hippo password=1234" -k
    SSH password:
    [WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.
    8.8.8.8 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": true,
        "comment": "",
        "create_home": true,
        "group": 1000,
        "home": "/home/hippo",
        "name": "hippo",
        "password": "NOT_LOGGING_PASSWORD",
        "shell": "/bin/bash",
        "state": "present",
        "system": false,
        "uid": 1000
    }

※ 경고 발생 → [WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.

  • password=1234로 하면 비밀번호가 암호화 되지 않아서 문제 발생
  • 1234의 암호화된 password가 저장되어야 ssh 접속할 때 1234로 로그인 가능

5. 파일 전송

  • 특정 파일을 모든 서버에 전달하는 방법
  • all : ansible 클라이언트의 모든 노드를 대상
  • -m 옵션 : 사용할 모듈을 지정하기 위한 옵션
  • copy 모듈 : ansible 클라이언트에게 파일을 전달하기 위해 사용하는 모듈
  • -a 옵션 : argument의 약어 copy에서 사용할 파일과 경로를 지정하는 옵션
  • src : 출발지를 의미 → /root/ 디렉토리에 있는 "sudo-1.9.5-3.el6.x86_64.rpm" 파일 전달
  • dest : 도착지를 의미 → ansible 클라이언트의 /root/ 디렉토리에 파일 저장
    ansible all -m copy -a "src=./sudo-1.9.5-3.el6.x86_64.rpm dest=/root/" -k
    SSH password:
    8.8.8.8 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": true,
        "checksum": "4fda41de00dddeb32445e1ea4d4dae1ba2c24d9a",
        "dest": "/root/sudo-1.9.5-3.el6.x86_64.rpm",
        "gid": 0,
        "group": "root",
        "md5sum": "801fda76d88f8c619a2a931f2e5e29d1",
        "mode": "0644",
        "owner": "root",
        "size": 2235944,
        "src": "/root/.ansible/tmp/ansible-tmp-1613809840.71-45665-17231553755106/source",
        "state": "file",
        "uid": 0
    }

6. 서비스 설치

  • lshw 설치
  • all : ansible 클라이언트의 모든 노드를 대상
  • -m 옵션 : 사용할 모듈을 지정하기 위한 옵션
  • yum 모듈 : ansible 클라이언트의 yum을 이용하여 yum 업데이트 및 패키지 설치
  • -a 옵션 : argument의 약어로 설치하거나 업데이트할 패키지를 지정하기 위해 옵션 사용
  • name : 패키지의 이름
  • state=present → 패키지를 설치
  • state : absent → 패키지를 삭제
    $ ansible all -m yum -a "name=lshw state=present" -k
    8.8.8.8 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": true,
        "changes": {
            "installed": [
                "lshw"
            ]
        },
        "msg": "",
        "rc": 0,
        "results": [
            "Loaded plugins: fastestmirror\\nLoading mirror speeds from cached hostfile\\n * base: mirror.kakao.com\\n * epel: mirror.krmir.org\\n * extras: mirror.kakao.com\\n * updates: mirror.kakao.com\\nResolving Dependencies\\n--> Running transaction check\\n---> Package lshw.x86_64 0:B.02.18-17.el7 will be installed\\n--> Finished Dependency Resolution\\n\\nDependencies Resolved\\n\\n================================================================================\\n Package        Arch             Version                   Repository      Size\\n================================================================================\\nInstalling:\\n lshw           x86_64           B.02.18-17.el7            base           324 k\\n\\nTransaction Summary\\n================================================================================\\nInstall  1 Package\\n\\nTotal download size: 324 k\\nInstalled size: 941 k\\nDownloading packages:\\nRunning transaction check\\nRunning transaction test\\nTransaction test succeeded\\nRunning transaction\\n  Installing : lshw-B.02.18-17.el7.x86_64                                   1/1 \\n  Verifying  : lshw-B.02.18-17.el7.x86_64                                   1/1 \\n\\nInstalled:\\n  lshw.x86_64 0:B.02.18-17.el7                                                  \\n\\nComplete!\\n"
        ]
    }

  • ansible 명령어에서 사용할 옵션들

1. -i (--inventory-file) → 적용될 호스트들에 대한 파일

  • 8.8.8.8 IP를 list 파일에 저장하면, 8.8.8.8에만 ansible 명령을 내림

    $ cd ~
    
    # 인벤토리 파일에 8.8.8.8 저장
    $ echo -e "8.8.8.8" > list
    $ cat list
    8.8.8.8
    
    # list 파일에 적힌 8.8.8.8에만 ping을 실행 (8.8.8.8은 테스트 IP)
    $ ansible all -i ~/list -m ping -k
    SSH password:
    8.8.8.8 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": false,
        "ping": "pong"
    }

2. -m (--module-name) → 모듈을 선택

  • ping은 ping 명령어가 아니라 python 모듈
  • 이미 사용자가 만들어 놓은 모듈을 사용하던가, 아니면 스스로 직접 만들어서 사용 가능

3. -k (--ask-pass) → 패스워드를 물어보도록 설정

  • ssh 접속할 때 암호가 있어야 접속이 가능

  • 암호가 저장되어 있지 않기 때문에 -k 옵션을 사용하지 않는 경우 ssh 접근이 안되어서 fail 발생

    # -k 옵션 사용 X -> 암호가 없기 때문에 ssh 접속에 실패하여 명령어 실행 X
    $ ansible all -m ping
    8.8.8.8 | UNREACHABLE! => {
        "changed": false,
        "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
        "unreachable": true
    }
    
    # -k 옵션 사용 -> 암호를 입력하여 ssh 접속 가능 (명령어 실행)
    $ ansible all -m ping -k
    SSH password:
    8.8.8.8 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": false,
        "ping": "pong"
    }

4. -K (--ask-become-pass) → 관리자로 권한 상승

  • root 계정을 사용하는 경우 사용 X
  • 유저 계정을 사용하는 경우 특정 명령어는 관리자 권한 상승이 필요

5. --list-hosts → 적용되는 호스트들을 확인

  • 명령어를 실행하기 전에 적용받을 호스트들을 확인 가능

  • 그룹에 따라 달라짐으로 실수를 방지하기 위해 미리 확인 필요

    # all은 모든 호스트들을 의미 -> 전체 호스트 확인 가능
    $ ansible all -m ping --list-hosts
      hosts (1):
        8.8.8.8
    
    # nginx 그룹에 적용된 호스트들을 확인 가능
    $ ansible nginx -m ping --list-hosts
      hosts (1):
        8.8.8.8
    
    # list 파일에 있는 호스트만 확인 가능
    $ ansible all -i ~/list -m ping --list-hosts
      hosts (1):
        8.8.8.8

  • ansible은 대상 서버들에 agent 설치 필요 X
  • ansible의 host 서버에만 설치하면, 관리 받는 대상 서버에 아무런 프로세스가 생행하지 않아도 됨
  • YAML 파일로 관리 받는 대상에 명령어 전달

ansible 서버에 ansible 설치 (ansible core 설치)

  • Centos7에서 사용
  • ansible 서버 : ansible 테스트 서버
  • ansible 클라이언트에는 다른 ansible 설치 필요 X
    $ yum install -y epel-release
    $ yum install -y ansible
  • ansible 설치 확인
    $ ansible --version
    ansible 2.9.27
    config file = /etc/ansible/ansible.cfg
    configured module search path = [u'/home/hippo/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/lib/python2.7/site-packages/ansible
    executable location = /usr/bin/ansible
    python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]


ansible 클라이언트에 tcp wrapper 설정과 iptables 설정

  • ansible 서버에서 클라이언트에 SSH 접속이 필요 → ansible은 SSH 포트 사용
  • tcp wrapper과 iptables 설정 필요
  • tcp wrapper 설정
    $ vi /etc/hosts.allow
    #ansible test
    ALL: [ansible 테스트 서버 IP]
  • iptables 설정

    # -A INPUT -p tcp -m tcp --dport 22 -j DROP 구문 위에 적용해야 ssh 접근 허용
    $ vi /etc/sysconfig/iptables
    -A INPUT -s [ansible 테스트 서버 IP] -p tcp -m tcp --dport 22 -j ACCEPT
    -A INPUT -p tcp -m tcp --dport 22 -j DROP
    
    # iptables 재실행
    $ systemctl restart iptables

포트 변경

  • ssh 접속할 수 있는 포트를 지정해야 ansible 코어 서버에서 접근 가능

  • 기본은 22번 포트

    $ vi /etc/ansible/ansible.cfg
    remote_port    = 22000
    #remote_port    = 22



출력되는 내용의 양식 결정

  • 기본은 skippy

  • debug로 표시하면 조금 더 가독성이 좋아짐

  • json으로 표시하면 json 파일 형태로 표시되어서 향후 웹서버에서 이용하기 편리함

    $ vi /etc/ansible/ansible.cfg
    stdout_callback = skippy
    #stdout_callback = debug
    #stdout_callback = json
  • json 파일을 적용하려면 stdout_callback = json으로 지정하고 난 뒤에 아래 부분도 변경해줘야함

    $ vi /etc/ansible/ansible.cfg
    #callback_whitelist = timer, mail
    callback_whitelist = json, timer



접속하는 서버의 /root/,ssh/known_hosts 파일에 접근 자동 저장

  • 처음 접속하는 서버는 known_hosts에 저장할 것인지 질의 → 질의에 대한 응답으로 yes를 해야만 ssh 접속이 가능

  • 수 많은 서버를 관리하는 입장에서 지속적으로 known_hosts에 저장하는 것은 번거로운 일이다.

  • 처음 서버에 접속하는 것에 대한 질의를 없애고 바로 known_hosts에 저장할 수 있도록 설정

    $ vi /etc/ansible/ansible.cfg
    ## 주석처리된 것을 삭제하면 됨
    ## host key checking setting above. 
    record_host_keys=False
    
    ## 주석처리된 것을 삭제하면 됨 
    ## uncomment this to disable SSH key host checking 
    host_key_checking = False



root로 직접 서버에 접속할 수 없는 경우 su 권한을 얻어서 서버에 적용

  1. become: 권한 상승 여부 (기본: True)

  2. become_method: 권한 상승 방법 (기본: sudo) →전체 적용되기에 보안상 위험해서 yml파일에 필요시 대입

  3. become_user: 권한 상승할 사용자 (기본: root)

  4. become_ask_pass: 권한 상승 방법의 패스워드 요청/입력 여부 (기본: false) -> yes로 변경해야 root 비밀번호도 입력 가능

    $ vi /etc/ansible/ansible.cfg
    ## 주석처리된 것을 삭제하면서 아래 내용과 같이 수정
    [privilege_escalation]
    become=True
    #become_method=su
    become_user=root
    become_ask_pass=True



ansible pipeline 설정

  • 파이프라인은 데이터 처리 단계의 출력이 다음 단계의 입력으로 이어지는 형태로 연결된 구조

  • 기존 (총 3번의 통신 필요)

    1. ssh 통신 : ~/.ansible/tmp 의 임시 저장 공간 생성
    2. sftp, scp, piped 통신 : 실행될 파일을 전달 (ansible-playbook )
    3. ssh 통신 : 실행
  • 파이프라이닝 옵션 적용 후

  • ssh 로 파일을 보냄과 동시에 실행

  • 적용 방법 → # pipelining = False의 주석을 제거하고 True로 변경

    $ vi /etc/ansible/ansible.cfg 
    # 주석처리된 것을 삭제하면서 아래 내용과 같이 수정
    # Enabling pipelining reduces the number of SSH operations required to
    # execute a module on the remote server. This can result in a significant
    # performance improvement when enabled, however when using "sudo:" you must
    # first disable 'requiretty' in /etc/sudoers
    #
    # By default, this option is disabled to preserve compatibility with
    # sudoers configurations that have requiretty (the default on many distros).
    #
    pipelining = True



ansible forks 설정

  • 한번에 실행하는 값

  • 운영체제에서는 System Call(fork)을 통해서 하나의 프로세스에서 자식 프로세스로 분기를 의미

  • pipelining을 통해 실행할때 forks = 5가 기본값으로 설정 (통로가 5개 만들어짐)

  • forks를 늘리면 자식 프로세스가 많아져서, 부하가 많이 발생할 수 있기에, 적절한 개수 설정이 필요

  • 부하 관련 참고 URL : https://medium.com/devops-srilanka/difference-between-forks-and-serial-in-ansible-48677ebe3f36

  • 적용 방법 → # pipelining = False의 주석을 제거하고 True로 변경

    $ vi /etc/ansible/ansible.cfg 
    # 주석처리된 것을 삭제하면서 아래 내용과 같이 수정
    forks          = 10

+ Recent posts