JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

ansible-yum模块 ansible replace模块

wys521 2024-10-20 11:45:08 精选教程 260 ℃ 0 评论


yum——repository
添加YUM仓库
name仓库名称,就是仓库文件中第一行的中括号名称,必须的参数
descrition 仓库描述信息,添加必须的参数
baseurl yum存储库“repodta”目录所在目录的URL,添加时必须的参数
他也可以是多个URL的李彪
file 仓库文件保存到本地的文件名,不包含.rep。默认是name的值
state preset确认添加仓库文件,absent确认删除仓库文件
ggcheck 是否检查GPG yes|no,没有默认值,使用/etc/yum.confd 中的配置

添加epel源

[root@bogon ~]# ansible web -m yum_repository -i hosts -a 'name=aliEpel description="alibaba EPEL" baseurl=https://mirrors.aliyun.com/epel/$releasever\Server/$basearch/'
192.168.216.132 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "repo": "aliEpel",
    "state": "present"
}
本地看一下
[root@bogon yum.repos.d]# ll
总用量 40
-rw-r--r--. 1 root   root    103 4月  23 16:58 aliEpel.repo
-rw-r--r--. 1 root   root   1664 11月 30 2016 CentOS-Base.repo
-rw-r--r--. 1 root   root   1309 11月 30 2016 CentOS-CR.repo
-rw-r--r--. 1 root   root    649 11月 30 2016 CentOS-Debuginfo.repo
-rw-r--r--. 1 root   root    314 11月 30 2016 CentOS-fasttrack.repo
-rw-r--r--. 1 root   root    630 11月 30 2016 CentOS-Media.repo
-rw-r--r--. 1 root   root   1331 11月 30 2016 CentOS-Sources.repo
-rw-r--r--. 1 root   root   2893 11月 30 2016 CentOS-Vault.repo
-rwxr-xr-x. 1 nobody nobody  353 4月  22 18:47 nginx.repocopy
-rw-r--r--. 1 root   root      7 4月  22 18:46 nginx.repocopy.4873.2022-04-22@18:47:10~
[root@bogon yum.repos.d]# cat aliEpel.repo
[aliEpel]
baseurl = https://mirrors.aliyun.com/epel/$releasever\Server/$basearch/
name = alibaba EPEL

删除源

[root@bogon ~]# ansible web -m yum_repository -a 'name=aliEpel  state=absent'                                                                         192.168.216.132 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "repo": "aliEpel",
    "state": "absent"
}
[root@bogon yum.repos.d]# cat aliEpel.repo
cat: aliEpel.repo: 没有那个文件或目录

yum模块
yum 模块可以帮助我们在远程主机上通过 yum 源管理软件包。

二、常用参数
name参数:必须参数,用于指定需要管理的软件包,比如 nginx。
state参数:用于指定软件包的状态 ,默认值为。present,表示确保软件包已经安装,除了。present,其他可用值有 installed、latest、absent、removed,其中 installed 与present 等效,latest 表示安装 yum 中最新的版本,absent 和 removed 等效,表示删除对应的软件包。
disable_gpg_check参数:用于禁用对 rpm 包的公钥 gpg 验证。默认值为 no,表示不禁用验证,设置为 yes 表示禁用验证,即不验证包,直接安装。在对应的 yum 源没有开启 gpg 验证的情况下,需要将此参数的值设置为 yes,否则会报错而无法进行安装。
enablerepo参数:用于指定安装软件包时临时启用的 yum 源。假如你想要从A源中安装软件,但是你不确定A源是否启用了,你可以在安装软件包时将此参数的值设置为 yes,即使A源的设置是未启用,也可以在安装软件包时临时启用A源。
disablerepo参数:用于指定安装软件包时临时禁用的 yum 源。某些场景下需要此参数,比如,当多个 yum 源中同时存在要安装的软件包时,你可以使用此参数临时禁用某个源,这样设置后,在安装软件包时则不会从对应的源中选择安装包。
enablerepo 参数和 disablerepo 参数可以同时使用。

安装一个软件包

[root@bogon ~]# ansible web -i hosts -m yum -a "name=nginx state=present disable_gpg_check=yes"
192.168.216.132 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "changes": {
        "installed": [
            "nginx"
        ]
    },
    "msg": "",
    "rc": 0,
    "results": [
        报一堆,自行欣赏
	]
}

ansible web -i hosts -m yum -a "name=nginx state=latest disable_gpg_check=yes"  如果是latest着会安装最新的软件包

你也可以使用state=installed  安装,或者remove卸载,跟linux命令一样
看一下客户端已经安装了nginx
[root@bogon yum.repos.d]# yum list installed |grep nginx
nginx.x86_64                          1:1.20.1-9.el7                   @aliEpel
nginx-filesystem.noarch               1:1.20.1-9.el7                   @aliEpel

卸载一个包

[root@bogon ~]# ansible web -i hosts -m yum -a "name=nginx state=absent "
192.168.216.132 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "changes": {
        "removed": [
            "nginx"
        ]
    },
    "msg": "",
    "rc": 0,
    "results": [
			报一堆,自行欣赏
	]
}


节点的nginx.x86_64  没了
[root@bogon yum.repos.d]# yum list installed |grep nginx
nginx-filesystem.noarch               1:1.20.1-9.el7                   @aliEpel

安装一个软件包组

[root@bogon ~]# ansible web -i hosts -m yum -a "name='@Development tools' state=installed disable_gpg_check=yes"
192.168.216.132 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "changes": {
        "installed": [
            "@Development tools"
        ]
    },
    "msg": "",
    "rc": 0,
    "results": [
       太多了,我就不做展示了
    ]
}
会输出一堆你可以从一堆里头发现它给你装了点啥
git.x86_64 0:1.8.3.1-23.el7_8 


然后在节点查一下,有的
[root@bogon yum.repos.d]# yum list installed |grep git.x86_64
git.x86_64                            1.8.3.1-23.el7_8                 @base

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表