본문 바로가기
Ansible

Ansible-Console

by Nirah 2023. 1. 9.

Ansible - Console 을 사용하면 일일이 -m 모듈 -a 아규먼트 -i 인벤토리 등을 지정해줄 필요 없이

대부분 리눅스 명령어를 그대로 쳐서 사용이 가능하다.

 

예를 들어 이렇게 hosts에 등록된 관리 노드 전체로 ping을 날릴수 있다.

ansible-console

ping

 

hosts 리스트를 출력시킨다.

list

특정 관리 노드 또는 그룹만 적용하려면 해당 디렉토리로 이동하듯이 cd를 쓰면 된다.

webservers 그룹원 목록만 보려면 다음과 같이 하면 된다. 

cd webservers

list

 

이외에 다음과 같이 hosts 파일에 등록된 객체들로 이동 가능이다.

전부 적용하려면 all로 이동하면 된다.

 

다음과 같이 유저계정 생성과 확인, 삭제도 그냥 리눅스 명령어와 같이 쓰면 된다.

 useradd kevin

tail /etc/passwd |egrep kevin

ls -l /home

userdel -r  kevin

 

다만 모든 명령어를 리눅스 콘솔에서 하듯히 해서 다 되는 것은 아니다.

일부 기능은 원래 ansible 명령어에서 -a 아규먼트 설정하듯이 지정해줘야 하거나 되는 방식이 따로 있다.

 

예를 들어 비밀번호 설정을 해보겠다.

passwd kevin

명령 실행이 안된다.

 

다음과 같이 한 줄에 비밀번호까지 다 집어넣어 해결할 수 있다.

 echo "It1" | passwd --stdin kevin

 

또 예를 들어 yum 명령어도 리눅스 콘솔과 똑같이는 안먹힌다.

yum install net-tools

기존 ansible 명령어처럼 arg(아규먼트) 을 조합하여 지정해줘야 작동한다.

yum name=net-tools state=present

 

아래와 같은 부분은 리눅스 명령어랑 똑같다.

systemctl enable --now httpd

systemctl status httpd | egrep -i active

firewalld permanent=yes service=http state=enabled

 

리눅스 명령어와 똑같다.

cp -v /etc/hosts /tmp/hosts

mv /tmp/hosts /tmp/hostlist

mv /tmp/hostlist /home/admin/

ls /home/admin

 

touch로 새 파일을 만들어보자

아래와 같이 touch 대신 state=touch 모듈 형식을 쓰는것을 권장한다고 친절하게 안내가 나오는 경우도 있다.

touch /home/admin/linux

권장은 권장이지 결과는 잘 만들어져 있다.

 

mkdir도 state=directory 를 써달라고 하지만 사실 만들어진다.

mkdir /home/admin/kubernetes

 

rm 도 state=absent를 써달라고 하지만 잘 지워진다.

rm -rf /home/admin/hosts

 

권한 변경을 해보자.

touch /tmp/hosts

chmod 644 /tmp/hosts

소유자 변경

chown admin: /tmp/hosts

ls -l /tmp/hosts

'Ansible' 카테고리의 다른 글

Ansible-Playbook  (0) 2023.01.09
Ansible-Vault  (0) 2023.01.09
Ansible 명령어 실습  (0) 2023.01.06
미니프로젝트- awx 설치  (0) 2023.01.05
Ansible 개념 / 설치  (0) 2023.01.05