ansible
-
ansible rolesansible 2022. 2. 6. 22:39
전체 디렉토리 구조 ├── ansible.cfg ├── inventories │ ├── dev │ ├── group_vars │ │ └── all.yml │ └── real ├── playbooks │ └── playbook.yml └── roles └── mysql ├── README.md ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml Role 디렉토리 만들기 위의 roles/mysql 하위 디렉토리 구조가 복..
-
ansible loopsansible 2022. 2. 6. 21:28
playbook 에 아래와 같이 작성할 수 있다. 예제1 - name: loop test hosts: web_servers tasks: - name: echo 1 to 3 command: echo {{ item }} loop: - 1 - 2 - 3 예제2 - name: loop test hosts: web_servers tasks: - name: touch sequence command: touch '/tmp/seq_{{ item.number }}_{{ item.char }}.txt' loop: - number: 1 char: a - number: 2 char: b - number: 3 char: c 구버전 ansible 에서는 loop 대신에 with_items 를 사용하기도 한다. 참고: https:..
-
ansible conditionalsansible 2022. 2. 6. 19:49
When 사용하기 예제1: OS 에 따라 package manager(apt / yum) 을 각각 다르게 사용하기 - name: Install NGINX hosts: web_servers tasks: - name: Install NGINX on Debian apt: name: nginx state: present when: ansible_os_family == "Debian" and ansible_distribution_version == "16.04" - name: Install NGINX on Redhat yum: name: nginx state: present when: ansible_os_family == "RedHat" or ansible_os_family == "SUSE" ansible_os_..
-
ansible variablesansible 2022. 2. 6. 15:43
inventory 에 정의하기 inventory.txt web1 ansible_host=192.168.0.17 [web_servers] web1 [web_servers:vars] SERVICE_PORT=8080 [all:vars] HOME_DIR='/home' playbook.yml - name: inventory variables hosts: web_servers tasks: - name: echo vars command: echo 'HOME_DIR={{ HOME_DIR }} SERVICE_PORT={{ SERVICE_PORT }}' register: result - name: echo result debug: msg={{ result['stdout_lines'] }} playbook 에 정의하기 pl..
-
ansible modulesansible 2022. 2. 6. 14:57
ansible module 참고하고, 자주 사용되는 module 을 나열해 보면 Command command script shell expect File file template copy find archive unarchive lineinfile System user group hostname ping systemd service mount make Database mysql postgresql More ... 참고: https://www.udemy.com/course/learn-ansible/
-
ansible playbooksansible 2022. 2. 6. 14:28
Playbook playbook.yml --- - name: playbook test hosts: localhost tasks: - name: Execute a command to display hosts file command: cat /etc/hosts - name: Execute script on server script: test_script.sh - name: Install httpd service yum: name: httpd state: present - name: Start web server service: name: httpd state: started Ansible-Playbook Command # ansible-playbook -i ansible-playbook -i inventor..
-
ansible inventoryansible 2022. 2. 5. 18:00
Inventory inventory.txt # Web Servers web1 ansible_host=server1.company.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Password123! web2 ansible_host=server2.company.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Password123! # Localhost localhost ansible_connection=localhost # Database Servers db1 ansible_host=server3.company.com ansible_connection=winrm ansible_us..