- ansible - 과 연관된 글 목록
Post
Ansible 정리 - variable
variables in playbook hosts:localhost vars: # variable 선언 dns_server: 10.1.1.10 tasks: - lineinfile: path: /etc/resolv.conf line: 'nameserver {{ dns_server }}' # variable 사용 variable을 저장하는 파일을 따로 만들 수도 있음, 또는 invertory file에다가 선언도 가능
web http_port=8081 snmp_port=161-162 http_port: 8081 snmp_port: 161-162 variable 사용법 source: {{ snmp_port }} <== 이건 안됨 soruce: ‘{{ snmp_port }}’ <== 가능 soruce: aaaa{{ snmp_port }}bbbb <== 가능
Post
Ansible 정리 - Modules
command module remote node에 command를 실행해주는 모듈
command module은 free_form parameter이다.
key=value pair parameter가 없어도 됨
자유롭게 parameter가 설정이 가능하다는 의미
- name: Run command if /path/to/database does not exist (without 'args'). command: /usr/bin/make_database.sh db_user db_name creates=/path/to/database copy module은 정해진 paramenter 만 들어감 (src, dest)
- name : Copy file copy: src=/source_file dest=/dest_file script module local에 있는 (ansible-controller) script를 원격에서 실행한다
servcie module 서비스를 재시작, 중지, 시작하는데 사용하는 모듈
tasks: - name: Start db service: name: postgresql state: started idempotency 멱등성: ansible에서 이 의미는
Post
Ansible 정리 - Intro
Ansible을 왜 쓰는거지? Ansible은 Universial 리모컨과 같다.
여러대의 윈도우, 또는 리눅스 머신을
하나의 PC에서 컨트롤을 가능하게 해준다
보통 한대의 controller와 하나 이상의 target이 존재한다.
그룹으로 묶어서 A그룹에는 A설정,
B그룹에는 B설정으로 배포가 가능하며,
유저 생성 등과 같은 시스템 설정도 가능하다.
윈도우도 된다고는 되어있지만, 리눅스처럼 잘될까 의문이 든다.
공부를 시작해보자! 두근 두근…
Post
Ansible 정리 - Inventory
Ansible 접속 방법 SSH or WinRM (powershell remoting)을 통해서 연결 agent가 필요 없다
inventory file 기본 위치 : /etc/ansible/hosts
서버 주소가 listing 되어있는 파일 (ini 형식비스무리)
server1.company.com server2.company.com [mail] server3.company.com server4.company.com [web] server5.company.com server6.company.com inventory with alias web ansible_host=server1.company.com ansible_connection=ssh db ansible_host=192.168.129.111 ansible_connection=winrm 그 외 inventory parameters ansible_host : 주소 ansible_connection : conneciton type(ssh/winrm/localhos) ansible_port : 포트 번호 (22/5986) ansible_user : root/administrator ansible_ssh_pass : ssh password ansible_password : winrm password # Web Servers web1 ansible_host=server1.
Post
Ansible 정리 - Playbook
Playbooks Ansible playbook은 YAML 파일 형식으로 되어있음 (docker-compose 처럼 생김)
- name: Play 1 hosts: localhost # inventory.txt 파일에 정의 되어있어야 한다. 만약 그룹이름이 들어가면 그 하위에 있는 모든 서버들에서 실행됨 tasks: - name: Execute command 'date' # 여기 리스트 부분은 순서에 따라 동작한다 (대시로 시작하는 부분은 list) command: date # 이 부분을 ansible module이라고 불림 - name: Execute script script: test_script.sh # 이 부분을 ansible module이라고 불림 - name: Play 2 hosts: localhost tasks: - name: Install web service yum: # 이 부분을 ansible module이라고 불림 name: httpd state: present - name: Start web server services: # 이 부분을 ansible module이라고 불림 name: httpd state: started 위에서 생성된 yml 파일을 아래 명령으로 실행한다