gather_facts // 우선 엔서블에서의 facts 란 클라이언트 서버 정보(OS버전같은거)다.  gather는 모으다. 즉 클라이언트 서버의 정보들(os 버전이나 이런것들)을 가져올꺼냐 안가져올꺼냐.. 정보가 필요하면 당연히 가져와야하고 필요없는 작업이면 안가져와도 된다. 속도차이가 있음


delegate_to // 인벤토리에 없는 호스트를 작업할 때 사용, 127.0.0.1(로컬)이 들어가있음 로컬 서버에 있는 쉘을 실행한다거나 그럴때 쓰임
run_once  // 위에 delegate_to 와 같이 자주 사용된다. delegate_to와 자주 사용되는이유는 실제 실행되는 서버에서 변수 한번 뽑으면 되는거니까
- name: test_delegate
  delegate_to: 127.0.0.1
  run_once: true
  command: /root/bin/tast_string
  register: test_exe


when   // if문같은거 옵션이 여러가지 많음
shell  // 쉘 실행
ignore_errors  // 에러나도 다음작업을 진행(ex. 백업해야할 때 mv로 파일을 옮겨야하는데 서버에 파일이 없으면 에러남, 이경우 백업할께 없으면 에러나도 상관없는거니까 mv로 진행)
  - name: centos 5 version mv test1sh cmd_test1.sh_date
    shell: mv /root/test1.sh /root/test1.sh_{{ansible_date_time.date}}
    when: ansible_distribution == "CentOS" and ansible_distribution_major_version == '5'
    ignore_errors: True

set_fact  // 변수 설정하는거임
- name: cur_time_var
  delegate_to: 127.0.0.1
  run_once: true
  set_fact: date_time="{{lookup('pipe','date \"+%Y%m%d\"')}}"


local_action // 로컬 서버에서 작업을 실행하겠다. delegate_to=127.0.0.1 이랑 같은건데 딜리게이트를 더 권장한다. 왜냐하면 로컬액션으로 처리가 안되는 것들이 많음
- name: cat ip
  local_action: shell cat /root/ip
  register: sip

register // task 실행 결과를 저장하고자 할 때에는 register 지시어를 사용하면 됨.
- name: IP check.
  shell: ip addr show eth0 | grep inet | grep -v inet6 | awk '{print $2}' | cut -d/ -f1
  register: real_ip

copy  //  말그대로 복사

lineinfile  // 이 모듈은 echo "문구" >> 파일.txt 와 같이 파일에 내용을 추가하는 모듈인데...ansible -m lineinfile "path=test.txt line=test11" 이런식으로 애드혹를 입력할경우 test.txt 하단에 test11이라는 구문이 추가된다.  근데 사람이 실수로 ansible -m lineinfile "path=test.txt line=test11" 이런 명령어를 두번 넣었을경우 lineinfile은 멱등성을 지원하기 때문에 해당 파일에 test11 이 두줄 추가 되지 않고 한줄만 추가된다. 
- name: password to /root/test
  lineinfile: dest=/root/test mode=0600 create=yes line="{{test.stdout}}"

with_items  // 반복처리할때 사용함, slave_ip.stdout_lines 리스트들

replace // 말그대로 단어교체 파일안의 내용들만 되는듯(mv 이름 이름.old 처럼 파일도 가능하진 않음)



debug // 말그대로 디버그, 이거는 status를 보기위한 용도로 한듯



'job > ansible' 카테고리의 다른 글

ansible - windows Win32ErrorCode 1058  (0) 2019.05.23
windows host에서 ansible 실행하는법  (0) 2019.05.23
ansible - 디렉토리 구조  (0) 2019.05.02
ansible- error  (0) 2019.04.26
ansible-3 playbook  (0) 2019.04.25

+ Recent posts