650) this.width=650; "Title=" Drawing 1.png "src=" http://s2.51cto.com/wyfs02/M01/85/EE/ Wkiom1evselisw8aaacilngjtgu249.png-wh_500x0-wm_3-wmp_4-s_1590913708.png "alt=" Wkiom1evselisw8aaacilngjtgu249.png-wh_50 "/>
1. Establish SSH non-secret key authentication relationship
Yum-y Install expect
1.1cat auto_deploy.sh
#!/bin/sh. /etc/init.d/functions#1.product key pairssh-keygen -t dsa -p ' -f ~/.ssh/id_dsa >/dev/null 2>&1 if [ $? -eq 0 ];then action "Create dsa success" /bin/true else action "Create dsa failed" /bin/false exit 1fi#2.dis pub keyfor ip in ' Cat ip.txt ' do expect expect_ fenfagongyao.exp ~/.ssh/id_dsa.pub $ip >/dev/null 2>&1 if [ $? -eq 0 ];then action "$ip" /bin/true else action "$ip" /bin/false fidone
1.2cat expect_fenfagongyao.exp
#!/usr/bin/expect if { $ARGC != 2 } { send_user "usege: expect expect_fenfagongyao.exp file host\n " exit }# #define varset file [lindex $argv 0]set host [lindex $argv 1]set password "123456" spawn ssh-copy-id -i $file "-p 22 [email protected" $host " expect { " Yes/no " {send " yes\r ";exp_continue} "*password" {send "$password \ r"} }expect eof exit -onexit { send_user "say good bye to You!\n "}
1.3 Cat Ip.txt
172.16.1.10172.16.1.27
2. Installing Ansible
Description: Using Yum installation, source package installation is particularly troublesome
2.1. Basic Settings
Yum-y Install Ansiblecd/etc/ansiblellansible.cfg #ansible的系统配置文件 The last addition to the hosts #客户端的主机的配置文件在/etc/ansible/hosts file: [w ebservers]172.16.1.10172.16.1.27
2.2 Viewing common modules
[[email protected] ansible]# ansible-doc -la10_server Manage A10 Networks AX/SoftAX/Thunder/vThunder devices a10_service_group manage a10 networks devices ' service groups a10_virtual_server manage a10 networks devices ' virtual servers acl Sets and retrieves file ACL information. add_host add a host (AND ALTERNATIVELY&NBsp;a group) to the ansible-playbook in-memory inventor...airbrake_deployment Notify airbrake about app deployments alternatives Manages alternative programs for common commands apache2_module enables/disables a module of the Apache2 webserver apk manages apk packages
2.2ansible Common Commands Summary
ansible webservers #webservers模块ansible all #所有的模块ansible webservers -m ping #查看主机存活状态 ansible webservers -m shell -a "bash /tmp/test.sh" #远程执行shell脚本, execute/tmp/test.sh script for client ansible webservers -m script -a '/root/run.sh ' #执行脚本/root/run.sh For local scripts ansible webservers -m command -a ' uptime ' #远程执行命令ansible webservers -m command -a ' yum -y install httpd ' #远程安装apacheansible webservers -m service -a ' name=httpd state=started ' name: Software name stated: started stoped restarted reloaded ansible webservers -m copy -a ' dest=/tmp src=/root/Run.sh ' #本机的/root/run.sh Copy to client/tmp ansible all -m cron -a ' name= ' Cron job " minute=*/5 hour=* day=* month=* weekday=* job="/usr/ Sbin/ntpdate time.nist.gov "' #定时任务ansible webservers -m file - a "Dest=/tmp/test.sh mode=777 owner=sanlang group=sanlang" #修改客户端文件权限 ansible -i /etc/ansible/hosts webservers -m setup # View the details of the client host ansible webservers -m file -a "src=/etc/fstab dest=/tmp/ Fstab state=link " #创建软连接
This article is from the "Brick Blog" blog, please be sure to keep this source http://wsxxsl.blog.51cto.com/9085838/1837689
Ansible installation and Common commands