Ansible - 조건적 실행 ( handler, when )
·
Infra/Ansible
[ Handler ]핸들러는 notify에 의해 호출되며 주로 서비스 재시작, 캐시클리어 등 후속 작업을 처리합니다.별로의 handler 폴더에 정의되어 실행할 수 있습니다.핸들러는 플레이북 실행 종료 시점에 호출됩니다.동일한 핸들러가 여러 태스크에서 호출되더라도 한번만 실행합니다.실행 순서는 notify에 나열된 순서가아니라 handler에 선언된 순서로 실행됩니다. [ Handler Example ]tasks:- name: Template configuration file ansible.builtin.template: src: template.j2 dest: /etc/foo.conf notify: - Restart apache - Restart memcachedhandlers..
Ansible - Inventory Build
·
Infra/Ansible
Invertory BasicsAnsible Inventory는 관리할 시스템 및 장비 목록을 정의한 파일입니다.이 파일을 통해 Ansible은 특정 호스트에 작업을 실행할 수 있습니다.기본적으로는 INI 또는 YAML 형식의 정적 파일을 사용하며, 동적 인벤토리도 지원합니다. hosts formatmail.example.com[webservers]foo.example.combar.example.com[dbservers]one.example.comtwo.example.comthree.example.comhosts.yaml formatungrouped: hosts: mail.example.com:webservers: hosts: foo.example.com: bar.example.com:..
Ansible - Playbook Roles 작성
·
Infra/Ansible
[ roles init ] roles directory 생성 $ mkdir roles $ cd rolse $ ansible-galaxy init common $ tree common ├── README.md ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml [ roles/common/vars/main.yml ] 미리 변수를 정의하여 tasks에서 사용 name: my-host [ roles/common/templat..
Ansible - ssh-key를 통한 비밀번호 없이 ssh접속
·
Infra/Ansible
# ssh/known_hosts 생성 ansible all -m ping -> yes로 # key생성 ssh-keygen -t rsa ls -al .ssh/ id_rsa id_rsa.pub known_hosts # key 복사 ssh-copy-id dgk@172.1.1.11 # 원격 접속후 pub파일 잘 복사됬는지 확인 ssh dgk@172.1.1.11 ls -al .ssh/ authorized_keys # 확인 ansible all -m ping
Ansible - 설치 및 실행
·
Infra/Ansible
/etc/sudoers 에 nopasswd 계정 추가 [ 앤서블 설치 ] $ yum install ansible -y 앤서블에서 사용 가능한 명령어 확인 $ ls /usr/bin/ansible* 노드들 주소 추가 $ vi /etc/ansible/hosts (추가) 192.1.1.1 192.1.1.2 192.1.1.3 known_hosts_key 값 입력 받음 $ ansible all -m ping (yes를 노드수만큼 입력) .... Are you sure you want to continue connecting (yes/no)? yes 정상적으로 노드들에게 명령 전달 확인 $ ansible all -m ping -k SSH password : (노드 비밀번호 입력) [ 앤서블 명령어 옵션 ] -m : ..
wave35
'Infra/Ansible' 카테고리의 글 목록