그룹관리

/etc/ansible/group_vars 하위에다가 그룹-그룹 그룹-변수 지정도 가능하다.

ansible]# cat /etc/ansible/hosts              
[nginx]
1.1.1.1         ansible_user=root       ansible_ssh_pass='qlqjs'
[apache]
2.2.2.2         ansible_user=root       ansible_ssh_pass='qlqjs'

파일 내용은 위와같고

ansible]# ansible all -m shell -a "df -h" --list-hosts
  hosts (2):
    1.1.1.1 
    2.2.2.2

 

ansible]# ansible nginx -m shell -a "df -h"   
1.1.1.1 | CHANGED | rc=0 >>
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       235G   37G  187G  17% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
/dev/sda1       200M  120M   70M  64% /boot

 

ansible]# ansible all -m shell -a "df -h"     
2.2.2.2 | FAILED | rc=-1 >>
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host.

1.1.1.1 | CHANGED | rc=0 >>
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       235G   37G  187G  17% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
/dev/sda1       200M  120M   70M  64% /boot

 

##
-m 옵션은 어떤 모듈을 선택할지..

yum, service, shell등 많다. -m 옵션의 기본값은 shell 이다. 다만 남들이 좀 더 보기 편하게 shell도 써주기

다만 위 명령들은 ansible 단일명령? 뭐 그런느낌이다. 에드혹이라고 하는듯. 대부분 플레이북을 이용해 사용한다.

-------여기까지가 가장 기본적인 ansible 사용법------------

 

----멱등성-----

엔서블하면 멱등성이 꼭 나온다.
멱등성이란 연산을 여러번 적용해도 결과가 달라지지 않는 성질인데 엔서블이 멱등성을 지원한다.
난 이부분이 처음에 굉장히 헷갈렸다. 도대체 어떻게 무조건 값이 같을 수 있지 ??근데 최대한 멱등성을 지원하려고 노력한다는거지(대부분의 모듈들이) 멱등성을 지원하지 않을수도 있다. 

여튼.. 멱등성이 뭔지 예를들자면 lineinfile 이란 모듈이 있다. 이 모듈은 echo "문구" >> 파일.txt 와 같이 파일에 내용을 추가하는 모듈인데...ansible -m lineinfile "path=test.txt line=test11" 이런식으로 애드혹를 입력할경우 test.txt 하단에 test11이라는 구문이 추가된다.  근데 사람이 실수로 ansible -m lineinfile "path=test.txt line=test11" 이런 명령어를 두번 넣었을경우 lineinfile은 멱등성을 지원하기 때문에 해당 파일에 test11 이 두줄 추가 되지 않고 한줄만 추가된다. 

반대로 shell 이라는 모듈을 통해 입력을 하면 당연히 test11이 두줄 추가 돼겠지. 이경우는 멱등성이 지원되지 않은거다.

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

ansible - 디렉토리 구조  (0) 2019.05.02
ansible- error  (0) 2019.04.26
ansible-3 playbook  (0) 2019.04.25
ansible-1  (0) 2019.04.10
ansible 공부  (0) 2018.10.10

+ Recent posts