IT/Ansible
[RHCSAA 교육 정리] 5 장 - 6장
트래이닝맨
2018. 3. 2. 07:16
728x90
반응형
5장 Task
with_items
- command: echo "{{item[0]}}" "{{item[1]}}" with_nested: - [ 'a', 'b'] - [ 'c', 'd', 'e'] |
with_file
with_fileglob
with_sequence ==> start와 end가 존재
with_random_choice
When 조건절
not available_memory
available_memory
test is defined
test is not defined
"abc" in groups
Handler
- 이름이 매우 중요
- 모든 task가 끝난 후에 실행된다.
- task 가 skip되면 handler도 skip된다.
Tags
- Special tags: tagged, untagged, all
- --skip-tags
- --tags
Error Handling
failed_when: "'Password missing' in command_result.stdout" 일단 실행은 되고 when절이 true면 fail result를 가지게 됨. To suppress that change, changed_when: false is set so that it only reports "ok" or "failed". changed_when: false 어떤 타스크는 실제 노드에 대해 변경을 하지 않는다 (ex, command: echo ) 이럴경우 강제로 changed 에서 ok 또는 failed로 나오게 한다. |
Block and Error Handling
- block:
rescue:
always:
6장 template
Jinja template
{% for user in users %} {{ user}} {% endfor %} {% if finished %} {{ result }} {% endif %} {% for myuser in users if not myuser == "Snoopy"%} {{loop.index}} - {{ myuser }} {% endfor %} |
중요한 Syntax
~~~ - hosts: app_servers vars: app_path: "{{ base_path }}/bin" <=== "가 꼭필요함 ~~~ ~~~ 잘못된것 .. - name: display the host value debug: msg: hostname = {{ params[ {{ host_ip }} ] }}, IPaddr = {{ host_ip }} .. .. 잘된것 - name: display the host value debug: msg: hostname = {{ params[ host_ip ] }}, IPaddr = {{ host_ip }} <=={{ 안에 {{ 이 있으면 안됨 ~~~ |
반응형