목록전체 글 (112)
컬쥐네 다락방
Artifact Artefact, Artifact: 인공물 애플리케이션이 작동해서 생성한 데이터 사람이 직접 작성한 코드 파일을 용도별로 구분을 해서 재사용하기 위함 변수 파일 작업 파일 플레이/플레이북 파일 역할(Role) 변수 파일 vars_files 플레이의 키워드 - hosts: x vars_files: - vars/a.yaml tasks: ...include_vars 모듈 - hosts: x tasks: - include_vars: dir: vars/인벤토리 변수 1. 인벤토리 내부 파일에 변수 설정 호스트 변수 node1 message="hello world"그룹 변수 [wordpress] node1 node2 [wordpress:vars] message="hello world"2. 인벤토리 ..
템플릿 주석 경고의 목적으로 사용된다 ansible.cfg 언제, 누가 어떻게 작성했는지에 관한 설명을 남긴다. [defaults] ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host} templates/port.cnf.j2 comment 필터를 사용하면 자동으로 남기도록 설정 가능. {{ ansible_managed | comment }} [mysqld] port={{ database["svc_port"] }}
블록 블록 = 여러 작업을 묶어 놓은 그룹 블록의 기능 여러 작업에 공통의 키워드를 부여할 수 있음(ex: 조건문) block, rescue, always 블록을 이용해 오류 처리를 할 수 있음 block 블록은 항상 실행 rescue 는 block 블록의 오류가 있을 때만 실행 always 는 항상 실행 - hosts: 192.168.100.11 tasks: - block: - debug: msg: hello world - command: /usr/bin/false - debug: msg: hello world2 ignore_errors: yes rescue: - debug: msg: It's rescue always: - debug: msg: It's Always태그 작업에 태그를 부여..
조건문 https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#basic-conditionals-with-when https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#playbooks-tests https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#playbooks-filters 작업에서 when 키워드 사용, 조건을 정의 test, filter 사용 If 문을 사용한다고 보면 된다. 조건 정의시 {{ }} 중괄호 사용 X - hosts: 192.168.100.11 ..
반복문 https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#playbooks-loops 작업(Task)에서 loop, with_, until 반복문 구성 여기서 사용되는 item은 흔히 사용되는 for문의 i이다.(ex for i in X 또는 for int i ; ;) 리스트(목록) 반복문 리스트를 사용해 다양한 방법으로 활용할 수 있다. loop 대신, with_items, with_list - hosts: 192.168.100.11 gather_facts: no tasks: - debug: msg: "{{ item }}" with_items: - apple - banana - carrot - hosts: 192.168.10..
변수 변수 정의 및 참조 template: src: foo.cfg.j2 dest: '{{ remote_install_path }}/foo.cfg' name: '{{ abc }}' dest: '{{ abc }}/abc.com' dest: '{{ abc }}'/abc.com #문법 오류 - hosts: 192.168.100.11 vars: msg: hello world tasks: - debug: var: msg - debug: msg: '{{ msg }} korea' - hosts: 192.168.100.11 vars: msg: hello world web: message: hello web fruits: - apple - banana tasks: - debug: msg: '{{ msg }} korea' ..
Ansible에서 Ad-hoc 명령을 통해 서버에 직접적으로 접속하지 않고도 여러 서버들을 관리할 수 있었다. 이런 방식을 yaml 파일을 통해 관리하고 정리하고 한번에 실행하는 방식이 Ansible의 Playbook이다. 야구 경기가 시작할 때 외치는 Playball에서 따왔다는 이야기가 있다. Playbook playbook: YAML 파일 .yaml, .yml play task test.yaml # Play - hosts: host1 tasks: # Task - yum: name: httpd state: installed # Task - service name: httpd state: started enabled: yes vim vim의 enhanced 모듈을 설치하면 탭키를 사용할 때 얼만큼 이동..
ad_hoc 명령 ansible -m -a https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html Wordpress 구성에 필요한 작업 패키지 설치: yum 서비스 제어: service 텍스트 수정: lineinfile, blockinfile, replace 압축: archive, unarchive 방화벽: firewalld, ufw, iptables 파일 복사: copy, fetch 파일 다운로드: get_url 데이터베이스 관리: mysql_db, mysql_user 파일 관리: file Ansible Jump Host with Bastion Host https://www.jeffgeerling.com/blog/2022/using..