728x90
아키텍처
구성 순서
1. Vagrantfile
2. Ansible_env_ready.yml
3. add_ssh_auth.sh
4. vagrant up
- Vagrantfile 실행
5. vagrant provision ansible-server
- Ansible_env_ready.yml, add_ssh_auth.sh 실행
Vagrantfile 작성
Ansible-Node03, Ansible-Node04 부분 추가
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant_API_Version = "2"
Vagrant.configure(Vagrant_API_Version) do |config|
# Ansible-Node01
config.vm.define:"ansible-node01" do |cfg|
cfg.vm.box = "centos/7"
cfg.vm.provider:virtualbox do |vb|
vb.name = "Ansible-Node01"
vb.customize ["modifyvm", :id, "--cpus",1]
vb.customize ["modifyvm", :id, "--memory",512]
end
cfg.vm.host_name = "ansible-node01"
cfg.vm.synced_folder ".", "/vagrant", disabled: true
cfg.vm.network "public_network", ip: "172.30.1.110"
cfg.vm.network "forwarded_port", guest: 22, host: 19211, auto_correct: false, id: "ssh"
cfg.vm.provision "shell", path: "bash_ssh_conf_4_CentOS.sh"
end
# Ansible-Node02
config.vm.define:"ansible-node02" do |cfg|
cfg.vm.box = "centos/7"
cfg.vm.provider:virtualbox do |vb|
vb.name = "Ansible-Node02"
vb.customize ["modifyvm", :id, "--cpus",1]
vb.customize ["modifyvm", :id, "--memory",512]
end
cfg.vm.host_name = "ansible-node02"
cfg.vm.synced_folder ".", "/vagrant", disabled: true
cfg.vm.network "public_network", ip: "172.30.1.120"
cfg.vm.network "forwarded_port", guest: 22, host: 19212, auto_correct: false, id: "ssh"
cfg.vm.provision "shell", path: "bash_ssh_conf_4_CentOS.sh"
end
# Ansible-Node03
config.vm.define:"ansible-node03" do |cfg|
cfg.vm.box = "ubuntu/trusty64"
cfg.vm.provider:virtualbox do |vb|
vb.name = "Ansible-Node03"
vb.customize ["modifyvm", :id, "--cpus",1]
vb.customize ["modifyvm", :id, "--memory",512]
end
cfg.vm.host_name = "ansible-node03"
cfg.vm.synced_folder ".", "/vagrant", disabled: true
cfg.vm.network "public_network", ip: "172.30.1.130"
cfg.vm.network "forwarded_port", guest: 22, host: 19213, auto_correct: false, id: "ssh"
end
# Ansible-Node04
config.vm.define:"ansible-node04" do |cfg|
cfg.vm.box = "ubuntu/trusty64"
cfg.vm.provider:virtualbox do |vb|
vb.name = "Ansible-Node04"
vb.customize ["modifyvm", :id, "--cpus",1]
vb.customize ["modifyvm", :id, "--memory",512]
end
cfg.vm.host_name = "ansible-node04"
cfg.vm.synced_folder ".", "/vagrant", disabled: true
cfg.vm.network "public_network", ip: "172.30.1.140"
cfg.vm.network "forwarded_port", guest: 22, host: 19214, auto_correct: false, id: "ssh"
end
# Ansible-Server
config.vm.define:"ansible-server" do |cfg|
cfg.vm.box = "centos/7"
cfg.vm.provider:virtualbox do |vb|
vb.name = "Ansible-Server"
end
cfg.vm.host_name = "ansible-server"
cfg.vm.synced_folder ".", "/vagrant", disabled: true
cfg.vm.network "public_network", ip: "172.30.1.100"
cfg.vm.network "forwarded_port", guest: 22, host: 19210, auto_correct: false, id: "ssh"
cfg.vm.provision "shell", path: "bootstrap.sh"
cfg.vm.provision "file", source: "Ansible_env_ready.yml", destination: "Ansible_env_ready.yml"
cfg.vm.provision "shell", inline: "ansible-playbook Ansible_env_ready.yml"
cfg.vm.provision "shell", path: "add_ssh_auth.sh", privileged: false
cfg.vm.provision "file", source: "Ansible_ssh_conf_4_CentOS.yml", destination: "Ansible_ssh_conf_4_CentOS.yml"
cfg.vm.provision "shell", inline: "ansible-playbook Ansible_ssh_conf_4_CentOS.yml"
end
end
Ansible_env_ready.yml 파일 수정
node03, node04 관련 코드 추가
---
- name: Setup for the Ansible's Environment
hosts: localhost
gather_facts: no
tasks:
- name: Add "/etc/hosts"
blockinfile: |
path=/etc/hosts
content="
172.30.1.100 server
172.30.1.110 node01
172.30.1.120 node02
172.30.1.130 node03
172.30.1.140 node04"
- name: Add "/etc/ansible/hosts"
blockinfile: |
path=/etc/ansible/hosts
content="
[CentOS]
node01
node02
[Ubuntu]
node03
node04"
- name: Install sshpass for Authentication
yum:
name: sshpass
state: present
- name: Install vim-enhanced
yum:
name: vim-enhanced
state: present
- name: Install git
yum:
name: git
state: present
- name: Download pathogen.vim
shell: "curl -fLo /home/vagrant/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim"
- name: Git clone vim-ansible-yaml
git:
repo: 'https://github.com/chase/vim-ansible-yaml.git'
dest: /home/vagrant/.vim/bundle/vim-ansible-yaml
- name: Configure vimrc
lineinfile:
path: /home/vagrant/.vimrc
line: "{{ item }}"
with_items:
- "set number"
- "execute pathogen#infect()"
- "syntax on"
- autocmd FileType yaml setlocal ts=2 sts=2 sw=2 et ai
- name: Configure Bashrc
lineinfile:
path: /home/vagrant/.bashrc
line: "{{ item }}"
with_items:
- "alias vi='vim'"
- "alias ans='ansible'"
- "alias anp='ansible-playbook'"
add_ssh_auth.sh 파일 수정
node03, node04 추가
#! /usr/bin/env bash
# ssh key 생성
sshpass -p vagrant ssh -T -o StrictHostKeyChecking=no vagrant@node01
sshpass -p vagrant ssh -T -o StrictHostKeyChecking=no vagrant@node02
sshpass -p vagrant ssh -T -o StrictHostKeyChecking=no vagrant@node03
sshpass -p vagrant ssh -T -o StrictHostKeyChecking=no vagrant@node04
vagrant up 실행
Vagrantfile이 실행됨
vagrant provision
Ansible_env_ready.yml 파일과 add_ssh_auth.sh 파일 실행
PS C:\HashiCorp\udemy-ansible> vagrant provision ansible-server
통신 확인
PS C:\HashiCorp\udemy-ansible> vagrant ssh ansible-server
Last login: Wed Jun 8 19:11:49 2022 from 10.0.2.2
[vagrant@ansible-server ~]$ ans all -m ping -k
728x90
'Ansible' 카테고리의 다른 글
220609_2_앤서블_심화_Known_hosts 자동 등록 (0) | 2022.06.10 |
---|---|
220609_1_앤서블_심화_실습 환경 구성-vagrant (0) | 2022.06.09 |
220608_5_앤서블_응용_NFS 서버와 클라이언트 구성 (0) | 2022.06.08 |
220608_4_앤서블_응용_timezone 설정 (0) | 2022.06.08 |
220608_3_앤서블_응용_앤서블 노드에 nginx 구성 (0) | 2022.06.08 |