Python environment and into the ansible
Python3.6 into the virtual environment
#su - deploy
#source .py3-a2.5-env/bin/activate
Load ansible 2.5 version
#source .py3-a2.5-env/ansible/hacking/env-setup -q
Verify ansible loading effect
#ansible-playbook --version
Write playbooks framework
Create a new directory and multiple directories
#mkdir test_playbooks
#cd test_playbooks/
#mkdir inventory roles
Into inventory, create testenv file,
# Cd inventory
#vi testenv
Add the target host service address
Return to the parent directory
#cd ../
Into the roles directory, create a subdirectory
#cd roles
#mkdir -p testbox/tasks
Enter the subdirectory, create main.yml files, playbooks as the main configuration file
#cd testbox/tasks/
#vi main.yml
Add test tasks, save and exit
Return to the test_playbooks directory
#cd ../../..
Playbooks create a task entry file, save and exit
#vi deploy.yml
Tree in print playbooks directory
#tree .
Configure key authentication ansible host and directory host
Returns the root user
#su - root
Edit hosts
#vi /etc/hosts
Add dns records test.example.com
Return deploy user
#exit
To deploy a user creates a key authentication
#ssh-keygen -t rsa
Enter has been
This time the public and private keys are generated in the same directory /home/deploy/.ssh/
Designated deploy user's public key
#ssh-copy-id -i /home/deploy/.ssh/id_rsa.pub [email protected]
Enter the target host password, you can establish a connection
Test connection to the host without a password
#ssh [email protected]
Testing is completed, the user is returned to deploy next
#exit
Test_playbooks into the directory, execute files under deploy.yml ansible-playbook. At this point execution is complete playbooks
#ansible-playbook -i inventory/testenv ./deploy.yml
Log on to the target host
#ssh [email protected]
View the current directory test.txt. Successful write parameters into the
#cat test.txt
Successfully music playing to the audience! !