공부합시다!/Ansible
Ansible을 활용한 vCenter 구성 자동화
간서치
2023. 11. 20. 17:04
728x90
우선 Locky Linux 9을 vCenter가 존재하는 host에 설치 후 아래 작업을 진행합니다.
1. 패키지 설치
2. pyvmomi 패키지 다운로드
3. 압축 및 Archive 해제
4. pyvmomi 설치
5. ansible 설치
6. community.vmware Collection 설치
7. Playbook 실행 후 오류 확인
# yum install -y tar wget epel-release python-pip
# wget https://files.pythonhosted.org/packages/ae/a4/70716f2fb132b105bc6cb4d4399491364582ab5690c87f19d6a9e4096037/pyvmomi-8.0.2.0.1.tar.gz
# tar xvfz pyvmomi-8.0.2.0.1.tar.gz
# ls
# cd pyvmomi-8.0.2.0.1
# python setup.py install
# dnf install ansible-core
# ansible-galaxy collection install community.vmware
# pip install requests
# vi folder.yml
---
- hosts: localhost
vars:
ansible_python_interpreter: /bin/python3
gather_facts: no
vcenter_hostname: "172.16.10.3"
vcenter_username: "administrator@team0.local"
vcenter_password: "VMware1!"
datacenter_name: "Datacenter"
project_id: "PRT-00"
parent_folder: "1.Projects"
tasks:
- name: 01. Create a Project folder
community.vmware.vcenter_folder:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
validate_certs: false
datacenter_name: '{{ datacenter_name }}'
folder_name: '{{ project_id }}'
# parent_folder: "4.Projects"
parent_folder: '{{ parent_folder }}'
state: present
register: sub_folder_creation_result
delegate_to: localhost
:wq
# ansible-playbook folder.yml
8. requests 모듈이 없음
9. pip를 이용하여 requests 모듈 설치
10. Playbook 실행 후 아래 폴더 생성 확인
728x90