티스토리 뷰

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 

 

force_handlers: yes

  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 }} <=={{ 안에 {{ 이 있으면 안됨
~~~





반응형

'IT > Ansible' 카테고리의 다른 글

[RHCSAA 교육 정리] 9 장 - 12 장  (0) 2018.03.02
[RHCSAA 교육 정리] 7 장 - 8장  (0) 2018.03.02
[RHCSAA 교육 정리] 3 장 - 4장  (0) 2018.03.02
[RHCSAA 교육 정리] 1 장 - 2장  (0) 2018.03.02
[RHCSAA]앤서블 자격증  (3) 2018.03.02
댓글
250x250
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함