IaC/Ansible

[Ansible] 앤서블로 yum 사용하는 방법

Nirsa 2021. 1. 4. 21:54
반응형
  • 앤서블로 yum 사용하는 방법

앤서블로 yum을 사용하는 방법 입니다. ansible 서버에서 아래 예시를 참고하여 yml 파일을 작성해 줍니다.

---
- name: Install vim and net-tools
  hosts: worker # 저는 /etc/ansible/hosts에 worker 라는 이름으로 그룹핑 해놨기 때문에 worker로 작성 하였습니다.
  gather_facts: no
  become: yes

  tasks:
    - name: install epel-release
      yum: name=epel-release state=latest  # epel 저장소 최신 버전으로 설치
    - name: install vim
      yum: name=vim state=present          # vim 설치
    - name: install net-tools
      yum: name=net-tools state=present    # net-tools 설치



# 삭제 예시
#    - name: install net-tools
#      yum: name=net-tools state=absent    # net-tools 삭제

 

이후 아래와 같이 ansible-playbook을 통해 실행한 후 정상적으로 worker들에게 설치가 된것을 확인할 수 있었습니다.

참고로 저의 경우 authorized_key 설정(nirsa.tistory.com/281?category=914087)을 해놧기에 -k 옵션 없이 명령어를 사용 하였으니 참고 해주세요.

ansible server
worker server

 

반응형