自动化-ansible安装rpm包管理服务
一:安装rpm包
列出所有模块:ansible-doc -l
查看指定的模块:ansible-doc cron
host1:192.168.1.251
1:使用ansible远程安装vim包
[root@ghs ~]# ansible 192.168.1.252 -m yum -a "name=vim-enhanced"
192.168.1.252 | SUCCESS => {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror\nSetting up Install Process\nLoading mirror speeds from cached hostfile\n * base: ftp.sjtu.edu.cn\n * extras: mirrors.163.com\n * updates: mirrors.163.com\nResolving Dependencies\n--> Running transaction check\n---> Package vim-enhanced.i686 2:7.4.629-5.el6_8.1 will be installed\n--> Processing Dependency: vim-common = 2:7.4.629-5.el6_8.1 for package: 2:vim-enhanced-7.4.629-5.el6_8.1.i686\n--> Processing Dependency: libgpm.so.2 for package: 2:vim-enhanced-7.4.629-5.el6_8.1.i686\n--> Running transaction check\n---> Package gpm-libs.i686 0:1.20.6-12.el6 will be installed\n---> Package vim-common.i686 2:7.4.629-5.el6_8.1 will be installed\n--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.629-5.el6_8.1.i686\n--> Running transaction check\n---> Package vim-filesystem.i686 2:7.4.629-5.el6_8.1 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n vim-enhanced i686 2:7.4.629-5.el6_8.1 base 976 k\nInstalling for dependencies:\n gpm-libs i686 1.20.6-12.el6 base 28 k\n vim-common i686 2:7.4.629-5.el6_8.1 base 6.7 M\n vim-filesystem i686 2:7.4.629-5.el6_8.1 base 15 k\n\nTransaction Summary\n================================================================================\nInstall 4 Package(s)\n\nTotal download size: 7.7 M\nInstalled size: 23 M\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal 909 kB/s | 7.7 MB 00:08 \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r Installing : 2:vim-filesystem-7.4.629-5.el6_8.1.i686 1/4 \n\r Installing : 2:vim-common-7.4.629-5.el6_8.1.i686 2/4 \n\r Installing : gpm-libs-1.20.6-12.el6.i686 3/4 \n\r Installing : 2:vim-enhanced-7.4.629-5.el6_8.1.i686 4/4 \n\r Verifying : 2:vim-enhanced-7.4.629-5.el6_8.1.i686 1/4 \n\r Verifying : 2:vim-filesystem-7.4.629-5.el6_8.1.i686 2/4 \n\r Verifying : 2:vim-common-7.4.629-5.el6_8.1.i686 3/4 \n\r Verifying : gpm-libs-1.20.6-12.el6.i686 4/4 \n\nInstalled:\n vim-enhanced.i686 2:7.4.629-5.el6_8.1 \n\nDependency Installed:\n gpm-libs.i686 0:1.20.6-12.el6 vim-common.i686 2:7.4.629-5.el6_8.1 \n vim-filesystem.i686 2:7.4.629-5.el6_8.1 \n\nComplete!\n"
]
}
name后面加需要安装的包名,name=vim-enhanced
host2:192.168.1.252:
1:使用rpm命令,查看是否有vim包
[root@ghs2 ~]# rpm -qa |grep vim
vim-common-7.4.629-5.el6_8.1.i686
vim-enhanced-7.4.629-5.el6_8.1.i686
vim-minimal-7.4.629-5.el6.i686
vim-filesystem-7.4.629-5.el6_8.1.i686
host1:192.168.1.251
1:使用ansible远程开启服务
state=stoppde
停止:stoppde
开启:started
开机启动:enabled
重启:restarted
重新加载:reloaded
开启httpd服务,开机启动
[root@ghs ~]# ansible 192.168.1.252 -m service -a "name=httpd state=started enabled=yes"
192.168.1.252 | SUCCESS => {
"changed": true,
"enabled": true,
"name": "httpd",
"state": "started"
}
验证
(192.168.1.252)
查看是否有httpd进程
[root@ghs2 ~]# ps aux|grep httpd
root 3267 0.0 0.3 11084 3436 ? Ss 15:21 0:00 /usr/sbin/httpd
apache 3271 0.0 0.2 11084 2192 ? S 15:21 0:00 /usr/sbin/httpd
apache 3272 0.0 0.2 11084 2204 ? S 15:21 0:00 /usr/sbin/httpd
apache 3273 0.0 0.2 11084 2192 ? S 15:21 0:00 /usr/sbin/httpd
apache 3274 0.0 0.2 11084 2192 ? S 15:21 0:00 /usr/sbin/httpd
apache 3275 0.0 0.2 11084 2192 ? S 15:21 0:00 /usr/sbin/httpd
apache 3276 0.0 0.2 11084 2192 ? S 15:21 0:00 /usr/sbin/httpd
apache 3277 0.0 0.2 11084 2192 ? S 15:21 0:00 /usr/sbin/httpd
apache 3278 0.0 0.2 11084 2192 ? S 15:21 0:00 /usr/sbin/httpd
root 3280 0.0 0.0 6052 776 pts/0 S+ 15:21 0:00 grep httpd
查看是否开机启动
[root@ghs2 ~]# chkconfig --list|grep httpd
httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
记录每一天有趣的事情!!