--Create Controller / Target node by node in Virtualbox --The range is from the controller to the Target by sending ansible playbook to the initial construction of the Target. --Change host name --Package installation (vim, git) --Ansible is installed as a module of virtualenv
--Python configuration management automation tool --In the form of defining the termination condition, it is characterized by idempotent guarantee (some commands need to be guaranteed by themselves) --Highly readable in YAML format playbook --Since there is no agent, the introduction cost is low (it is OK if SSH and python are included in the management target) ――It goes well with the use of self-made scripts that have already been created. ――Module development / role development at 3rd Party is active, and most of what I want to do is in Documents / ansible-galaxy. - modules : http://docs.ansible.com/ansible/modules.html - roles : https://galaxy.ansible.com/ --Push type configuration management is common -Convert YAML format playbook to python and distribute / execute to managed target
Term | Description |
---|---|
Inventory | Specify Target Node. INI format |
Playbook | Describe the flow of processing you want to execute on Target Node. YAML format |
Created by general users
useradd -s /bin/bash -m ansible
passwd ansible
#Grant sudo privileges
echo "ansible ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/ansible
su - ansible
cd ~
ssh-keygen
ssh-copy-id -i .ssh/id_rsa.pub 192.168.56.152 (Target Node IP address)
Install command
su - ansible
sudo yum -y install epel-release
sudo yum -y install gcc libffi-devel python-devel openssl-devel python-pip
sudo pip install --upgrade pip
#Not required if virtualenv is not used
sudo pip install virtualenv
#Not required if virtualenv is not used
cd ~
virtualenv venv
source venv/bin/activate
pip install "ansible==2.2"
Creating a working directory
su - ansible
cd ~
mkdir -p practice/{inventory,{group,host}_vars,roles,playbooks}
touch practice/{inventory/inventory.ini,group_vars/all.yml}
Creating an Inventory file
su - ansible
cd ~/practice
vim inventory/inventory.ini
inventory/inventory.ini
[practice_servers]
practice01 ansible_host=192.168.56.152 #Target Node
Communication confirmation
#Confirm that the server information of Target Node is returned as Response
ansible practice_servers -i inventory/inventory.ini -m setup
Playbook creation
su - ansible
cd ~/practice
vim playbooks/initial_setting.yml
~/practice/playbooks/initial_setting.yml
---
- hosts: practice_servers
become: yes #Implement sudo on Target server
become_user: root #Performed on behalf of the root user
tasks:
- name: 1. Set hostname
hostname:
name: practice01
- name: 2. Install required packages
yum:
name: "{{ item }}"
with_items:
- vim
- git
Run playbook
su - ansible
cd ~/practice
ansible-playbook -i inventory/inventory.ini playbooks/initial_setting.yml
Controller
Vagrant.configure("2") do |config|
# Basic VM settings
config.vm.box = "CentOS7.0"
config.vm.box_download_insecure = true
config.vm.hostname = 'controller'
config.vm.network "private_network",ip:"192.168.56.151"
config.vm.network :public_network, bridge: 'en0: Wi-Fi (AirPort)'
config.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2151
config.ssh.insert_key = false
# Virtual box setting
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--ostype", "Redhat_64"]
vb.name = "ansible_controller"
vb.memory = 512
vb.cpus = 1
end
end
Target_Node
Vagrant.configure("2") do |config|
# Basic VM settings
config.vm.box = "CentOS7.0"
config.vm.box_download_insecure = true
config.vm.hostname = 'practice'
config.vm.network "private_network",ip:"192.168.56.152"
config.vm.network :public_network, bridge: 'en0: Wi-Fi (AirPort)'
config.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2152
config.ssh.insert_key = false
# Virtual box setting
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--ostype", "Redhat_64"]
vb.name = "practice"
vb.memory = 512
vb.cpus = 1
end
end
Recommended Posts