우리는 컨트롤러에서 어떤 인벤토리에게 어떤 플레이북을 실행시킬 것이냐!
ssh-keygen
엔터 3번
ssh-copy-id root@매니지드노드IP
패스워드
ssh root@매니지드노드IP 했을 때 패스워드 없이 접속 가능
yum install -y epel-release
wget [ansible-2.8.8-1.el8.noarch.rpm]
yum install -y ansible-2.8.8-1.el8.noarch.rpm
all:
children:
server:
hosts:
200.200.200.202
db:
hosts:
200.200.200.203
ansible [그룹이름] -i [인벤토리파일경로] -m ping
#앤서블 명령어를 실행할 때 -i 옵션으로 파일 지정 가능
- hosts: ["server", "db"] [그룹]
tasks:
- name: Linux Command [이름]
shell: |
touch /root/ansible_test [명령어]
become: yes
- name: Linux Command2
shell: |
touch /root/ansible_test2
become: yes
ansible-playbook -i /root/test/hosts /root/test/playbook
ansible-playbook -i [인벤토리경로] [모듈이작성된플레이북경로]
- hosts: ["server", "db"]
tasks:
- name: change chmod1 [이름]
file:
path: "/root/ansible_test" "[경로]"
mode: 0755 [권한]
become: yes
- name: change chmod2
file:
path: "/root/ansible_test2"
mode: 0755
become: yes
- hosts: ["server", "db"]
tasks:
- name: Download apach-tomcat
get_url:
url: https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.73/bin/apache-tomcat-9.0.73.tar.gz [다운받을 url]
dest: /tmp/apache-tomcat-9.0.73.tar.gz [어디다 저장할거냐?]
become: yes
- name: Install tomcat
unarchive:
src: "/tmp/apache-tomcat-9.0.73.tar.gz" [어떤걸 풀거냐?]
dest: "/usr/local" [어디다 압축을 해제할거냐?]
remote_src: yes [컨트롤러에만 있냐 없냐]
become: yes
- name: Move
command: mv /usr/local/apache-tomcat-9.0.73 /usr/local/tomcat9 [리눅스 명령어]
- 띄어쓰기를 잘못해서 계속 에러가 발생 yml파일의 경우 들여쓰기가 문법이기 떄문에 주의!
- TAP도 사용하면 안된다!
- hosts: ["server", "db"]
tasks:
- name: "copy file"
copy:
src: /root/test/file/{{ item }}
dest: /root/{{ item }}
remote_src: no
with_items:
- file1
- file2
- file3
become: yes
<Connector protocol="AJP/1.3"
address="{{ ansible_all_ipv4_addresses[0] }}"
secretRequired="false"
port="8009"
redirectPort="8443" />
ansible-galaxy init [롤이름]