문법
반복문
- name: Make OpenSSL backup directory
file:
path: "{{ item }}"
state: directory
owner: root
group: root
loop:
- /opt/app
- /opt/app/log
변수
- Using Variables — Ansible Documentation
- 기본적으로 yml 문법
something_var: "val"
- 호출시
target: "{{ something_var }}"
작업
생성 / 디렉토리
- name: Creates directory
file:
path: /src/www
state: directory
- name: Creates directory
file:
path: /src/www
state: directory
owner: www-data
group: www-data
mode: 0775
recurse: yes
삭제
- name: Remove self
file:
dest: "{{ item }}"
state: "absent"
with_items:
- "{{ config }}"
- "{{ backup }}"
- "{{ log }}"
복사
호스트 to 원격
- name: Copy all
copy:
src: ./
dest: <destination_dir>
- name: copy consul_ui files
command: cp -r /home/{{ user }}/dist/{{ item }} /usr/share/nginx/html
with_items:
- "index.html"
- "static/"
이동
- name: stat foo
stat: path=/path/to/foo
register: foo_stat
- name: Move foo to bar
command: mv /path/to/foo /path/to/bar
when: foo_stat.stat.exists
원격 to 원격
- name: Copy
copy:
src: ./
dest: <destination_dir>
remote_src: yes
명령어 실행
- name: Create CSR
command: >
openssl req -new
-key {{ ssl }}
-out {{ ssl_csr }}
-subj "{{ ssl_self_signed_subject }}"
-passout pass: -passin pass:""
- loop 호출
- name: run some commands
command: "{{ multicmd_item }}"
loop:
- /usr/sbin/foobar -x param1
- /usr/sbin/foobar -a param1 -b param2 -c param3
- /usr/sbin/foobar -d para1 -e "param2" "param3"
loop_control:
loop_var: multicmd_item
아카이브 파일
- name: Extract
unarchive:
src: "{{ target_path }}target.tar.gz"
dest: "{{ target_path }}"
remote_src: yes
하위 작업 호출
- include_tasks: ssl_self_signed.yml
기타
템플릿
Assert
ansible.builtin.assert module – Asserts given expressions are true — Ansible Documentation
- name: Check
assert:
that:
- '"{{ application_output.stdout }}" == "{{ target_application_stdout }}"'
fail_msg: "{{ application_output.stdout }}"
핸들러
notify:
- regen pem
태그
tags:
- haproxy-ssl