ansile模块之yum
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansile模块之yum相关的知识,希望对你有一定的参考价值。
ansible yum 使用yum软件包管理器安装,升级,删除和列出软件包和组。
参数来自官网,如有出入,以官网为准
参数 | 是否必须 | 默认 | 选项 | 说明 |
conf_file | no | 用于事务的远程yum配置文件。 | ||
disable_gpg_check | no | yes no | 是否禁用GPG检查正在安装的软件包的签名。只有当状态存在或最新时才有效。 | |
disablerepo | no | 复制存储库以禁用安装/更新操作。这些回购将不会持续到事务之外。指定多个回购时,请用“,”分隔它们。 | ||
enablerepo | no | 复制存储库以禁用安装/更新操作。这些回购将不会持续到事务之外。指定多个回购时,请用“,”分隔它们。 | ||
exclude | no | 当state = present或latest时要排除的包名称 | ||
list | no | 用于/usr/bin/ansible而不是playbook的各种(非幂等)命令。参见示例。 | ||
name | yes | 软件包名称或带有版本的软件包说明符,如name-1.0。当使用state = latest时,这可以是‘*‘,这意味着运行:yum -y update。您还可以将url或本地路径传递到rpm文件(使用state = present)。要操作多个包,可以接受逗号分隔的包列表或(从2.0开始)包列表。 | ||
state | no | present | present installed latest absent removed | 是否安装(提供或安装,最新)或删除(不存在或删除)包。 |
update_cache | no | no | yes no | 强制更新高速缓存。只有当状态存在或最新时才有效。 |
validate_certs | no | yes | yes no | 这仅适用于使用https url作为rpm的源。例如为localinstall。如果设置为“否”,则不会验证SSL证书。 这应该只设置为在个人控制的站点上使用自签名证书,因为它避免验证源站点。 在2.1之前,代码的工作方式就像这个设置为yes。 |
安装httpd包
# ansible webserver -m yum -a "name=httpd state=present" 172.16.110.48 | SUCCESS => { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nLoading mirror speeds from cached hostfile\n * base: mirrors.163.com\n * extras: ftp.sjtu.edu.cn\n * updates: mirrors.aliyun.com\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.4.6-45.el7.centos base 2.7 M\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal download size: 2.7 M\nInstalled size: 9.4 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n\nInstalled:\n httpd.x86_64 0:2.4.6-45.el7.centos \n\nComplete!\n" ] } 172.16.110.47 | SUCCESS => { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nLoading mirror speeds from cached hostfile\n * base: mirrors.aliyun.com\n * extras: mirrors.aliyun.com\n * updates: ftp.sjtu.edu.cn\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.4.6-45.el7.centos base 2.7 M\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal download size: 2.7 M\nInstalled size: 9.4 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n\nInstalled:\n httpd.x86_64 0:2.4.6-45.el7.centos \n\nComplete!\n" ] }
2.卸载httpd包
# ansible webserver -m yum -a "name=httpd state=absent" 172.16.110.48 | SUCCESS => { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nRemoving:\n httpd x86_64 2.4.6-45.el7.centos @base 9.4 M\n\nTransaction Summary\n================================================================================\nRemove 1 Package\n\nInstalled size: 9.4 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Erasing : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n\nRemoved:\n httpd.x86_64 0:2.4.6-45.el7.centos \n\nComplete!\n" ] } 172.16.110.47 | SUCCESS => { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nRemoving:\n httpd x86_64 2.4.6-45.el7.centos @base 9.4 M\n\nTransaction Summary\n================================================================================\nRemove 1 Package\n\nInstalled size: 9.4 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Erasing : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n Verifying : httpd-2.4.6-45.el7.centos.x86_64 1/1 \n\nRemoved:\n httpd.x86_64 0:2.4.6-45.el7.centos \n\nComplete!\n" ] }
3.安装开发环境包
# ansible webserver -m yum -a "name=‘@Development tools‘ state=present" 172.16.110.47 | SUCCESS => { "changed": false, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nLoading mirror speeds from cached hostfile\n * base: mirrors.aliyun.com\n * extras: mirrors.aliyun.com\n * updates: ftp.sjtu.edu.cn\nResolving Dependencies\n--> Running transaction check\n---> Package autoconf.noarch 0:2.69-11.el7 will be erased\n---> Package automake.noarch 0:1.13.4-3.el7 will be erased\n---> Package bison.x86_64 0:2.7-4.el7 will be erased\n---> Package byacc.x86_64 0:1.9.20130304-3.el7 will be erased\n---> Package cscope.x86_64 0:15.8-9.el7 will be erased\n---> Package ctags.x86_64 0:5.8-13.el7 will be erased\n---> Package diffstat.x86_64 0:1.57-4.el7 will be erased\n---> Package doxygen.x86_64 1:1.8.5-3.el7 will be erased\n---> Package flex.x86_64 0:2.5.37-3.el7 will be erased\n---> Package gcc.x86_64 0:4.8.5-11.el7 will be erased\n--> Processing Dependency: gcc for package: systemtap-devel-3.0-7.el7.x86_64\n--> Processing Dependency: gcc for package: systemtap-devel-3.0-7.el7.x86_64\n--> Processing Dependency: gcc = 4.8.5-11.el7 for package: libquadmath-devel-4.8.5-11.el7.x86_64\n---> Package gcc-c++.x86_64 0:4.8.5-11.el7 will be erased\n---> Package gcc-gfortran.x86_64 0:4.8.5-11.el7 will be erased\n---> Package git.x86_64 0:1.8.3.1-6.el7_2.1 will be erased\n--> Processing Dependency: git for package: gettext-devel-0.18.2.1-4.el7.x86_64\n--> Processing Dependency: git = 1.8.3.1-6.el7_2.1 for package: perl-Git-1.8.3.1-6.el7_2.1.noarch\n---> Package indent.x86_64 0:2.2.11-13.el7 will be erased\n---> Package intltool.noarch 0:0.50.2-6.el7 will be erased\n---> Package libtool.x86_64 0:2.4.2-21.el7_2 will be erased\n---> Package patch.x86_64 0:2.7.1-8.el7 will be erased\n---> Package patchutils.x86_64 0:0.3.3-4.el7 will be erased\n---> Package rcs.x86_64 0:5.9.0-5.el7 will be erased\n---> Package redhat-rpm-config.noarch 0:9.1.0-72.el7.centos will be erased\n---> Package rpm-build.x86_64 0:4.11.3-21.el7 will be erased\n---> Package rpm-sign.x86_64 0:4.11.3-21.el7 will be erased\n---> Package subversion.x86_64 0:1.7.14-10.el7 will be erased\n---> Package swig.x86_64 0:2.0.10-5.el7 will be erased\n---> Package systemtap.x86_64 0:3.0-7.el7 will be erased\n--> Running transaction check\n---> Package gettext-devel.x86_64 0:0.18.2.1-4.el7 will be erased\n---> Package libquadmath-devel.x86_64 0:4.8.5-11.el7 will be erased\n---> Package perl-Git.noarch 0:1.8.3.1-6.el7_2.1 will be erased\n---> Package systemtap-devel.x86_64 0:3.0-7.el7 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package ..... 172.16.110.48 | SUCCESS => { "changed": false, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nLoading mirror speeds from cached hostfile\n * base: mirrors.163.com\n * extras: ftp.sjtu.edu.cn\n * updates: mirrors.aliyun.com\nResolving Dependencies\n--> Running transaction check\n---> Package autoconf.noarch 0:2.69-11.el7 will be erased\n---> Package automake.noarch 0:1.13.4-3.el7 will be erased\n---> Package bison.x86_64 0:2.7-4.el7 will be erased\n---> Package byacc.x86_64 0:1.9.20130304-3.el7 will be erased\n---> Package cscope.x86_64 0:15.8-9.el7 will be erased\n---> Package ctags.x86_64 0:5.8-13.el7 will be erased\n---> Package diffstat.x86_64 0:1.57-4.el7 will be erased\n---> Package doxygen.x86_64 1:1.8.5-3.el7 will be erased\n---> Package flex.x86_64 0:2.5.37-3.el7 will be erased\n---> Package gcc.x86_64 0:4.8.5-11.el7 will be erased\n--> Processing Dependency: gcc for package: systemtap-devel-3.0-7.el7.x86_64\n--> Processing Dependency: gcc for package: systemtap-devel-3.0-7.el7.x86_64\n--> Processing Dependency: gcc = 4.8.5-11.el7 for package: libquadmath-devel-4.8.5-11.el7.x86_64\n---> Package gcc-c++.x86_64 0:4.8.5-11.el7 will be erased\n---> Package gcc-gfortran.x86_64 0:4.8.5-11.el7 will be erased\n---> Package git.x86_64 0:1.8.3.1-6.el7_2.1 will be erased\n--> Processing Dependency: git for package: gettext-devel-0.18.2.1-4.el7.x86_64\n--> Processing Dependency: git = 1.8.3.1-6.el7_2.1 for package: perl-Git-1.8.3.1-6.el7_2.1.noarch\n---> Package indent.x86_64 0:2.2.11-13.el7 will be erased\n---> Package intltool.noarch 0:0.50.2-6.el7 will be erased\n---> Package libtool.x86_64 0:2.4.2-21.el7_2 will be erased\n---> Package patch.x86_64 0:2.7.1-8.el7 will be erased\n---> Package patchutils.x86_64 0:0.3.3-4.el7 will be erased\n---> Package rcs.x86_64 0:5.9.0-5.el7 will be erased\n---> Package redhat-rpm-config.noarch 0:9.1.0-72.el7.centos will be erased\n---> Package rpm-build.x86_64 0:4.11.3-21.el7 will be erased\n---> Package rpm-sign.x86_64 0:4.11.3-21.el7 will be erased\n---> Package subversion.x86_64 0:1.7.14-10.el7 will be erased\n---> Package swig.x86_64 0:2.0.10-5.el7 will be erased\n---> Package systemtap.x86_64 0:3.0-7.el7 will be erased\n--> Running transaction check\n---> Package gettext-devel.x86_64 0:0.18.2.1-4.el7 will be erased\n---> Package libquadmath-devel.x86_64 0:4.8.5-11.el7 will be erased\n---> Package perl-Git.noarch 0:1.8.3.1-6.el7_2.1 will be erased\n---> Package systemtap-devel.x86_64 0:3.0-7.el7 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package ......
4.安装远程仓库nginx
# ansible webserver -m yum -a "name=http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.2-1.el7.ngx.x86_64.rpm state=present" 172.16.110.48 | SUCCESS => { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nExamining /tmp/tmpUR6G0V/nginx-1.10.2-1.el7.ngx.x86_64.rpm: 1:nginx-1.10.2-1.el7.ngx.x86_64\nMarking /tmp/tmpUR6G0V/nginx-1.10.2-1.el7.ngx.x86_64.rpm to be installed\nResolving Dependencies\n--> Running transaction check\n---> Package nginx.x86_64 1:1.10.2-1.el7.ngx will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n nginx x86_64 1:1.10.2-1.el7.ngx /nginx-1.10.2-1.el7.ngx.x86_64 2.2 M\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal size: 2.2 M\nInstalled size: 2.2 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : 1:nginx-1.10.2-1.el7.ngx.x86_64 1/1 \n----------------------------------------------------------------------\n\nThanks for using nginx!\n\nPlease find the official documentation for nginx here:\n* http://nginx.org/en/docs/\n\nCommercial subscriptions for nginx are available on:\n* http://nginx.com/products/\n\n----------------------------------------------------------------------\n Verifying : 1:nginx-1.10.2-1.el7.ngx.x86_64 1/1 \n\nInstalled:\n nginx.x86_64 1:1.10.2-1.el7.ngx \n\nComplete!\n" ] } 172.16.110.47 | SUCCESS => { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nExamining /tmp/tmpj81JF6/nginx-1.10.2-1.el7.ngx.x86_64.rpm: 1:nginx-1.10.2-1.el7.ngx.x86_64\nMarking /tmp/tmpj81JF6/nginx-1.10.2-1.el7.ngx.x86_64.rpm to be installed\nResolving Dependencies\n--> Running transaction check\n---> Package nginx.x86_64 1:1.10.2-1.el7.ngx will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n nginx x86_64 1:1.10.2-1.el7.ngx /nginx-1.10.2-1.el7.ngx.x86_64 2.2 M\n\nTransaction Summary\n================================================================================\nInstall 1 Package\n\nTotal size: 2.2 M\nInstalled size: 2.2 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : 1:nginx-1.10.2-1.el7.ngx.x86_64 1/1 \n----------------------------------------------------------------------\n\nThanks for using nginx!\n\nPlease find the official documentation for nginx here:\n* http://nginx.org/en/docs/\n\nCommercial subscriptions for nginx are available on:\n* http://nginx.com/products/\n\n----------------------------------------------------------------------\n Verifying : 1:nginx-1.10.2-1.el7.ngx.x86_64 1/1 \n\nInstalled:\n nginx.x86_64 1:1.10.2-1.el7.ngx \n\nComplete!\n" ] }
5.升级所有包
]# ansible webserver -m yum -a "name=* state=latest" 172.16.110.47 | SUCCESS => { "changed": false, "msg": "", "rc": 0, "results": [ "Nothing to do here, all packages are up to date" ] } 172.16.110.48 | SUCCESS => { "changed": false, "msg": "", "rc": 0, "results": [ "Nothing to do here, all packages are up to date" ] }
本文出自 “深呼吸再出击” 博客,请务必保留此出处http://ckl893.blog.51cto.com/8827818/1887270
以上是关于ansile模块之yum的主要内容,如果未能解决你的问题,请参考以下文章