목차
Ansible ad-hoc 개요
- Ad-hoc 소개
- Ad-hoc 명령은 /usr/bin/ansible 명령 행 도구를 사용하여 하나 이상의 관리 노드에서 단일 태스크를 자동화 합니다.
- Ad-hoc 명령은 쉽고 빠리지만 재사용 할 수 는 없습니다.
- Ad-hoc 명령을 사용하는 이유
- 박복적이지 않은 작업에 유용합니다. (설정 정보 확인 및 Shell명령어 실행 등)
- 사용 사례
- 서버 재부팅
- 파일 관리
- 패키지 관리
- 사용자 및 그룹 관리
- 서비스 관리
- 설정 정보 확인
연결상태 확인 PING
[devops@work-vm devops-lab]$ ansible web -m ping
처리 결과
web01-vm | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } web03-vm | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } web02-vm | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" }
디스크 용량 확인
디스크 용량 확인
[devops@work-vm devops-lab]$ ansible web -m shell -a "df -h"
web01-vm | CHANGED | rc=0 >> Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 1.2G 29G 5% / devtmpfs 948M 0 948M 0% /dev tmpfs 960M 0 960M 0% /dev/shm tmpfs 960M 9.0M 951M 1% /run tmpfs 960M 0 960M 0% /sys/fs/cgroup /dev/sda1 497M 81M 417M 17% /boot /dev/sdb1 3.9G 16M 3.7G 1% /mnt/resource tmpfs 192M 0 192M 0% /run/user/1000 web03-vm | CHANGED | rc=0 >> Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 1.2G 29G 5% / devtmpfs 948M 0 948M 0% /dev tmpfs 960M 0 960M 0% /dev/shm tmpfs 960M 9.0M 951M 1% /run tmpfs 960M 0 960M 0% /sys/fs/cgroup /dev/sda1 497M 81M 417M 17% /boot /dev/sdb1 3.9G 16M 3.7G 1% /mnt/resource tmpfs 192M 0 192M 0% /run/user/1000 web02-vm | CHANGED | rc=0 >> Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 1.2G 29G 5% / devtmpfs 948M 0 948M 0% /dev tmpfs 960M 0 960M 0% /dev/shm tmpfs 960M 9.0M 951M 1% /run tmpfs 960M 0 960M 0% /sys/fs/cgroup /dev/sda1 497M 81M 417M 17% /boot /dev/sdb1 3.9G 16M 3.7G 1% /mnt/resource tmpfs 192M 0 192M 0% /run/user/1000
메모리 상태 확인
메모리 상태 확인
[devops@work-vm devops-lab]$ ansible web -m shell -a "free -h"
web01-vm | CHANGED | rc=0 >> total used free shared buff/cache available Mem: 1.9G 155M 1.5G 8.9M 227M 1.5G Swap: 0B 0B 0B web03-vm | CHANGED | rc=0 >> total used free shared buff/cache available Mem: 1.9G 158M 1.5G 8.9M 227M 1.5G Swap: 0B 0B 0B web02-vm | CHANGED | rc=0 >> total used free shared buff/cache available Mem: 1.9G 158M 1.5G 8.9M 230M 1.5G Swap: 0B 0B 0B
신규 유저 추가
[devops@work-vm devops-lab]$ ansible web -m user -a "name=bloter password=1qazxsw23edC"
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly. web01-vm | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "comment": "", "create_home": true, "group": 1001, "home": "/home/bloter", "name": "bloter", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", "state": "present", "system": false, "uid": 1001 } web02-vm | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "comment": "", "create_home": true, "group": 1001, "home": "/home/bloter", "name": "bloter", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", "state": "present", "system": false, "uid": 1001 } web03-vm | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "comment": "", "create_home": true, "group": 1001, "home": "/home/bloter", "name": "bloter", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", "state": "present", "system": false, "uid": 1001 }
[devops@work-vm devops-lab]$ ansible web -m shell -a "cat /etc/passwd | grep bloter" web01-vm | CHANGED | rc=0 >> bloter:x:1001:1001::/home/bloter:/bin/bash web02-vm | CHANGED | rc=0 >> bloter:x:1001:1001::/home/bloter:/bin/bash web03-vm | CHANGED | rc=0 >> bloter:x:1001:1001::/home/bloter:/bin/bash
특정PORT Listen확인
[devops@work-vm devops-lab]$ ansible web -m shell -a "netstat -nltp | grep httpd"
web01-vm | CHANGED | rc=0 >> tcp6 0 0 :::80 :::* LISTEN 69884/httpd web03-vm | CHANGED | rc=0 >> tcp6 0 0 :::80 :::* LISTEN 68690/httpd web02-vm | CHANGED | rc=0 >> tcp6 0 0 :::80 :::* LISTEN 70096/httpd
2 Comments
Anonymous
Anonymous
Add Comment