Operation and maintenance of automation - ansible master batch management

2000--2016 years, the maintenance of minicomputers, linux beginning of 2 units to thousands, manual inspection, the daily version upgrade requires too much equipment management, operation and maintenance must be achieved through automation

In particular version upgrade, you need to deploy code similar machines, start-stop device, the code must be completed on a master distribution, from the remote service stops, service verification verify

2016 started with pssh, after the switch ansible, ansible configuration is as follows

First, configure the ssh password free

#cd /root/.ssh

Free interactive generate the key

#echo -e "\n" |ssh-keygen -t rsa -N ""

Send to lock the machine web1

# Ssh-copy-id -i /root/.ssh/id_rsa.pub root @ web1, as follows

[root@fox .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@web1
The authenticity of host 'web1 (192.168.80.131)' can't be established.
RSA key fingerprint is 9c:c0:e2:2b:6f:88:c8:b1:25:47:f6:4b:fa:8f:cd:00.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'web1,192.168.80.131' (RSA) to the list of known hosts.
root@web1's password:

[root@fox ~]# sed -i 's#fox#web01#g' /etc/sysconfig/network
[root@fox ~]# more /etc/sysconfig/network

Note: If a different machine, automatic answer when needed, can be expect software, expect to see usage check

https://www.cnblogs.com/yangmingxianshen/p/7967040.html

 

Second, the installation ansible

1. Master yum third party source side installation EPEL
# RPM -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm
2. Installation Ansible
# yum install ansible -y
appears Error: Can not retrieve metalink for repository :. epel Please verify its path and try again
solution: word: the /etc/yum.repos.d/epel.repo, file row 3 Notes removed, the fourth line commented out.
Open /etc/yum.repos.d/epel.repo, the
[EPEL]
name = Extra Packages Standard Package for Enterprise Linux 6 - $ basearch
# baseurl = HTTP: //download.fedoraproject.org/pub/epel/6/$basearch
? mirrorlist = https: //mirrors.fedoraproject.org/metalink repo = epel-6 & arch = $ basearch
changed to
[EPEL]
name = Extra Packages Standard Package for Enterprise Linux 6 - $ basearch
baseurl = HTTP: //download.fedoraproject.org/ pub / epel / 6 / $ basearch
HTTPS mirrorlist = #: //mirrors.fedoraproject.org/metalink EPEL-repo = 6 & Arch = $ basearch?
3. And then clean up the source, re-install
yum clean all
this time successful installation
# yum install ansible -y

Note: Reference to solve the problem https://www.cnblogs.com/dadong616/p/5062727.html

Three, ansible use

1. Remote command module command: performing remote host SHELL command (which is on a remote machine commands)

# ansible webservers -m command -a "free -m"

2.script:. Remote execution MASTER local SHELL script (similar to scp + shell) Note that this script should be placed MASTER, very useful command

#echo "hostname" > /tmp/test1.sh
#chmod 700 /tmp/test1.sh

# ansible web -m script -a "/tmp/test1.sh"

web1 | SUCCESS => {
"changed": true, 
"rc": 0, 
"stderr": "Shared connection to web1 closed.\r\n", 
"stderr_lines": [
"Shared connection to web1 closed."
], 
"stdout": "web01\r\n", 
"stdout_lines": [
"web01"
]
}

 

Other modules and usage, see https://www.cnblogs.com/cheyunhua/p/8151603.html

 

to sum up:

1. Use tools to improve efficiency

2 script tidy, ready to use

3 for routine upgrade, a key deployment environment, rapid diagnosis and other occasions

Guess you like

Origin www.cnblogs.com/micfox/p/10992999.html