[Ansible] Install Ansible – 앤서블 설치

install ansible

Ansible은 오픈소스 프로젝트여서 누구나 비용 없이 설치해서 사용할 수 있습니다. 이번 글에서는 오픈소스 Ansible과 레드햇에서 지원하는 Ansible을 설치하는 방법을 안내하도록 하겠습니다.

환경

  • Redhat Enterprise Linux 8 이상
  • ansible 8.4.0
  • ansible-core 2.15.4

사전 요구사항

ansible 8버전과 ansible-core 2.15 버전 설치를 위해서는 python3.9 이상이 설치되어 있어야 합니다.

레드햇에서 파이썬 설치하는 방법은 파이썬 설치 사이트에서 확인할 수 있습니다.

Version Support End Of Life Control Node Python Target Python / PowerShell
https://github.com/ansible/ansible/blob/stable-2.15/changelogs/CHANGELOG-v2.15.rst GA: 22 May 2023Critical: 06 Nov 2023Security: 20 May 2024 Nov 2024 Python 3.9 – 3.11 Python 2.7Python 3.5 – 3.11PowerShell 3 – 5.1
https://github.com/ansible/ansible/blob/stable-2.14/changelogs/CHANGELOG-v2.14.rst GA: 07 Nov 2022Critical: 22 May 2023Security: 06 Nov 2023 20 May 2024 Python 3.9 – 3.11 Python 2.7Python 3.5 – 3.11PowerShell 3 – 5.1
https://github.com/ansible/ansible/blob/stable-2.13/changelogs/CHANGELOG-v2.13.rst GA: 23 May 2022Critical: 07 Nov 2022Security: 22 May 2023 06 Nov 2023 Python 3.8 – 3.10 Python 2.7Python 3.5 – 3.10PowerShell 3 – 5.1

앤서블 버전

커뮤니티 앤서블 버전은 2.9 버전부터 크게 2가지로 분리되었습니다. 수천 개의 모듈과 수십 개 이상의 컬렉션을 포함하는 Ansible community package 버전과 필수 컬렉션만 포함된 ansible-core 버전으로 나뉩니다.

참고: https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html

Ansible commnuity package 방식은 이전부터 사용하던 방식입니다. 앤서블에서 사용되는 모든 모듈이 제품 자체에 포함돼서 나오는 방식이며 이를 배터리 포함이라고 부릅니다. 이와 반대로 ansible-core 버전은 최소한의 모듈만 포함돼서 제품이 출시됩니다. 기존 ansible 방식에서는 새로운 모듈을 사용하기 위해 ansible 다음 업데이트에 모듈이 포함되기를 기다려야 했습니다. ansible-core는 사용자들이 최신 업데이트된 모듈을 컬렉션 형태로 바로 설치해서 사용하는 방식이므로 빠르게 발전하는 오픈소스 환경에서 효과적인 방법입니다.

레드햇에서 지원하는 앤서블 설치

레드햇은 앤서블을 2가지 방식으로 제공합니다. 하나는 RedHat Enterprise Linux에 포함되어 있는 ansible-core이며 다른 하나는 AAP(Ansible Automation Platform)이라는 서브스크립션에서 제공됩니다. 그러므로 RHEL 사용자가 단순 ansible-core만 사용할 경우 별도의 AAP 구매 없이 사용할 수 있습니다. 설치를 위해서는 서브스크립션 또는 local repo 설정이 필요하며 RHEL 8.6 이상에서 RPM 패키지로 제공됩니다.

Local Repo설정 방법은 “로컬 레포 구축”을 참조하시면 됩니다.

  • 설치
    # dnf install ansible-core
    Updating Subscription Management repositories.
    Unable to read consumer identity
    
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    
    OS                                                                                                                                         137 MB/s | 2.4 MB     00:00    
    APP                                                                                                                                        117 MB/s | 8.1 MB     00:00    
    Last metadata expiration check: 0:00:01 ago on Tue 03 Oct 2023 03:11:49 AM KST.
    Dependencies resolved.
    ===========================================================================================================================================================================
     Package                                               Architecture                     Version                                  Repository                           Size
    ===========================================================================================================================================================================
    Installing:
     ansible-core                                          x86_64                           2.14.2-3.el8                             local-APP                           3.4 M
    Installing dependencies:
     git-core                                              x86_64                           2.39.1-1.el8                             local-APP                            10 M
     mpdecimal                                             x86_64                           2.5.1-3.el8                              local-APP                            93 k
     python3.11                                            x86_64                           ...
    
    Complete!
    
  • 버전 확인
    # ansible --version
    ansible [core 2.14.2]
      config file = /etc/ansible/ansible.cfg
      configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python3.11/site-packages/ansible
      ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
      executable location = /usr/bin/ansible
      python version = 3.11.2 (main, Feb 17 2023, 09:28:16) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.11)
      jinja version = 3.1.2
      libyaml = True
    

커뮤니티 버전 앤서블 설치

커뮤니티 버전은 최소한의 모듈이 포함된 ansible-core 버전과 수많은 모듈과 컬렉션이 포함된 ansible 버전 두 개로 나뉩니다. 여기 서는 ansible-core와 ansible 두 개를 모두 설치해 보고 모듈 개수를 비교해 보도록 하겠습니다. 사용하려는 용도에 맞게 하나를 선택해서 설치하시면 됩니다. 일반적으로 ansible-core를 설치 후에 필요한 기능을 다운로드해 사용하시는 방법을 권장 드립니다.

ansible-core 설치

ansible-core는 2.10 → 2.11 → 2.12 → 2.13 → 2.14 → 2.15 형식으로 업데이트되고 있으며 2023년 10월 기준 최신 버전은 2.15.4 버전입니다.

  • 파이썬 버전 확인
    # python3 --version
    Python 3.9.2
    
  • ansible 설치
    # python3 -m pip install --user ansible-core
    WARNING: Running pip install with root privileges is generally not a good idea. Try `python3 -m pip install --user` instead.
    ...
      WARNING: The scripts ansible, ansible-config, ansible-connection, ansible-console, ansible-doc, ansible-galaxy, ansible-inventory, ansible-playbook, ansible-pull and ansible-vault are installed in '/root/.local/bin' which is not on PATH.
      Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
    Successfully installed MarkupSafe-2.1.3 PyYAML-6.0.1 ansible-core-2.15.4 cffi-1.16.0 cryptography-41.0.4 importlib-resources-5.0.7 jinja2-3.1.2 packaging-23.2 pycparser-2.21 resolvelib-1.0.1
    

    ansible-core가 설치 후에 WARNING 경고가 발생합니다. 설치 프로그램은 ansible 명령어를 “/root/.local/bin” 디렉터리에 저장했는데 PATH 환경 변수에 해당 디렉터리가 없으므로 시스템 전역 명령어로 사용할 수 없다는 에러입니다.

    문제를 해결하기 위해 “/root/.local/bin” 디렉터리를 PATH에 추가해 주도록 하겠습니다.

    # vim /etc/profile
    ...
    export PATH=/root/.local/bin:$PATH
    
    # su -
    

    PATH 환경 변수는 “PATH 환경 변수” 내용을 참조하시면 됩니다.

  • 앤서블 버전 확인ansible-core 2.15.4 버전이 설치되었습니다. ansible-core는 ansible 명령어를 포함하고 있습니다.
    # ansible --version
    ansible [core 2.15.4]
      config file = None
      configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /root/.local/lib/python3.9/site-packages/ansible
      ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
      executable location = /root/.local/bin/ansible
      python version = 3.9.2 (default, Mar 10 2021, 17:29:56) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] (/usr/bin/python3)
      jinja version = 3.1.2
      libyaml = True
    
  • 모듈 확인설치된 모듈을 확인해 보면 기본적으로 포함된 70개 정도의 모듈이 검색됩니다.
    # ansible-doc -l
    ansible.builtin.add_host               Add a host (and alternatively a grou...
    ansible.builtin.apt                    Manages apt-packages                
    ansible.builtin.apt_key                Add or remove an apt key            
    ansible.builtin.apt_repository         Add and remove APT repositories     
    ansible.builtin.assemble               Assemble configuration files from fr...
    ansible.builtin.assert                 Asserts given expressions are true  
    ansible.builtin.async_status           Obtain status of asynchronous task  
    ansible.builtin.blockinfile            Insert/update/remove a text block su...
    ansible.builtin.command                Execute commands on targets
    ...
    
    # ansible-doc -l | wc -l
    74
    
  • 설치된 컬렉션 확인ansible-core 제품에는 최소 모듈만 포함되어 있기 때문에 설치된 컬렉션이 없습니다. 따라서 테스트 용으로 aws 컬렉션을 하나 설치한 뒤 목록을 조회해 보도록 하겠습니다.
    # ansible-galaxy collection install amazon.aws
    Starting galaxy collection install process
    Process install dependency map
    Starting collection install process
    Downloading <https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/amazon-aws-6.4.0.tar.gz> to /root/.ansible/tmp/ansible-local-496422ahknfhn/tmpyu6nfmhi/amazon-aws-6.4.0-_6oq5k3y
    Installing 'amazon.aws:6.4.0' to '/root/.ansible/collections/ansible_collections/amazon/aws'
    amazon.aws:6.4.0 was installed successfully
    
    # ansible-galaxy collection list
    
    # /root/.ansible/collections/ansible_collections
    Collection Version
    ---------- -------
    amazon.aws 6.4.0
    

Ansible Community Package 설치

ansible 버전은 2.10 → 3 → 4 → 5 → 6 → 7 → 8 형식으로 업데이트되고 있으며 2023년 10월 현재 8버전까지 출시되었습니다.

  • 파이썬 버전 확인
    # python3 --version
    Python 3.9.2
    
  • ansible 설치
    # python3 -m pip install --user ansible
    ...
    Installing collected packages: resolvelib, PyYAML, packaging, pycparser, cffi, cryptography, importlib-resources, MarkupSafe, jinja2, ansible-core, ansible
    Successfully installed MarkupSafe-2.1.3 PyYAML-6.0.1 ansible-8.4.0 ansible-core-2.15.4 cffi-1.16.0 cryptography-41.0.4 importlib-resources-5.0.7 jinja2-3.1.2 packaging-23.2 pycparser-2.21 resolvelib-1.0.1
    

    설치된 패키지 목록을 확인해 보면 ansible-core와 ansible 두 개 모두 설치된 것을 보실 수 있습니다. 설치가 정상적으로 됐는지 버전을 확인해 보겠습니다.

    # ansible-community --version
    Ansible community version 8.4.0
    
    # ansible --version
    ansible [core 2.15.4]
      config file = None
      configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
      ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
      executable location = /usr/local/bin/ansible
      python version = 3.9.2 (default, Mar 10 2021, 17:29:56) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] (/usr/bin/python3)
      jinja version = 3.1.2
      libyaml = True
    

ansible 8.4.0 버전이 설치가 되었으며 ansible-core 버전 2.15.4 버전도 함께 설치가 잘 되었습니다. ansible community package 버전에 포함된 컬렉션과 모듈 정보를 살펴보겠습니다.

컬렉션 목록을 조회해 보면 100개 이상의 컬렉션이 설치된 부분을 보실 수 있습니다. 출력 결과는 너무 길어서 생략했습니다.

# ansible-galaxy collection list

# /usr/local/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    6.4.0  
ansible.netcommon             5.2.0  
ansible.posix                 1.5.4  
ansible.utils                 2.11.0 
ansible.windows               1.14.0 
arista.eos                    6.1.0
...

# ansible-galaxy collection list | wc -l
111

또한 8천 개 이상의 모듈이 설치된 부분도 확인할 수 있습니다.

# ansible-doc -l
amazon.aws.autoscaling_group               Create or delete AWS Aut...
amazon.aws.autoscaling_group_info          Gather information about EC2 Auto Scalin...
amazon.aws.aws_az_info                     Gather information about ava...
...

# ansible-doc -l | wc -l
8266

마치며

레드햇에서 제공하는 ansible-core와 커뮤니티에서 제공하는 ansible-core 그리고 ansible을 설치해 봤습니다. 레드햇 사용 고객이라면 레드햇 지원이 가능한 RPM 패키지 설치를 권장 드립니다. 또한 앤서블은 오픈소스로 제공되고 있으므로 기술 지원이 필요하지 않다면 별도의 구매가 필요 없습니다.

 

참조

https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#id11

https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html

댓글 달기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

Scroll to Top