본문 바로가기

네트워크/네트워크 자동화

[4] Ansible 활용하기 기초편

  1. uptime 확인하기
  2. 디스크 용량 확인하기
  3. 메모리 상태 확인하기
  4. 새로운 유저 만들기
  5. 파일 전송하기
  6. 서비스 설치

uptime 확인하기

[root@AnsibleServer ~]# ansible all -m shell -a "uptime" -k

shell이라는 모듈을 사용하고, uptime이라는 argument를 보냄

 

Disk 용량 확인하기

[root@AnsibleServer ~]# ansible all -m shell -a "df -h" -k

 

Memory 용량 확인하기

[root@AnsibleServer ~]# ansible all -m shell -a "free -h" -k

이렇게 기존에 사용하는 shell 명령어로 중앙에서 관리하는 노드들의 상태들을 쉽게 확인할 수 있음!!!!

 

User 만들기 - user라는 모듈있음.

[root@AnsibleServer ~]# ansible nginx -m user -a "name=mimi password=1234" -k

바로 로그인은 안됨.. 유저가 만들어졌는지 확인하려면 root로 접근 후에

[root@ansible-node02 ~]# vi /etc/passwd

위에 접속하고 가장 마지막 보면 있음.

왜 ssh 로 로그인되지 않을까? 중앙에서 그냥 암호화도 없이 뿌려진 암호이기 때문에 중간에 탈취하거나 그럴 위험이 있어서 암호화, 복호화 작업이 이루어진 것만 로그인될 수 있음..

 

파일 전송하기

일단 보내야할 파일 만들기

[root@AnsibleServer ~]# vi lauren.txt
(아무거나 적은 후 저장...)
"hello"
[root@AnsibleServer ~]# ansible nginx -m copy -a "src=/root/lauren,txt dest=/root/" -k

그 다음 위에 처럼 보내면 될 줄 알았는데 안보내짐...ㅠㅠ

Could not find or access '/root/lauren,txt' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option   <-- 이런 에러가 뜸...

[root@AnsibleServer ~]# ansible nginx -m copy -a "src=/root/lauren.file dest=/root/" -k

이게 source file이 .file이 확장자 여나 봅니다...ㅠㅠ

 

전송 잘 된 것을 확인할 수 있음.

 

서비스를 원격으로 설치하기(apache deamon 설치하기)

[root@AnsibleServer ~]# ansible nginx -m yum -a "name=httpd state=present" -k

value of state must be one of: absent, installed, latest, present, removed, got: prasent

이것도 이런 문제가 발생함..

왜냐면 노드들이 DNS 설정이 되어있지 않기 때문임..!!!!

전에 중앙 서버에서 설정한 config 파일을 노드들에게 전송함

[root@AnsibleServer ~]# cat /etc/resolv.conf

# Generated by NetworkManager

nameserver 219.250.36.130
[root@AnsibleServer ~]# ansible nginx -m copy -a "src=/etc/resolv.conf dest=/etc/" -k

그 다음 다시 위의 명령어로 설치함(ansible nginx -m yum -a "name=httpd state=present" -k)

잘 설치되는 것을 확인할 수 있음!!!!

노드에서도 잘 설치되어있는 것을 확인 할 수 있음. 아직 httpd가 실행되지는 않음

설치하고 바로 실행하는 건 다음 시간에~~