zoukankan      html  css  js  c++  java
  • ansible通过yum/dnf模块给受控机安装软件(ansible2.9.5)

    一,使用yum/dnf模块要注意的地方:

    使用dnf软件安装/卸载时,需要有root权限,

    所以要使用become参数

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

    说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,用yum模块卸载软件

    #name:软件的名字

    #state: 状态,取值有:present:默认的,表示为安装
                               lastest: 安装为最新的版本
                               absent:表示删除

    [liuhongdi@centos8 ~]$ ansible yujian -m yum -a 'name=screen state=absent' --become  --become-method=sudo --become-user=root
    121.122.123.47 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": true,
        "msg": "",
        "rc": 0,
        "results": [
            "Removed: screen-4.6.2-10.el8.x86_64"
        ]
    }

    三,用yum模块安装软件:

    [liuhongdi@centos8 ~]$ ansible yujian -m yum -a 'name=screen' --become  --become-method=sudo --become-user=root
    121.122.123.47 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": true,
        "msg": "",
        "rc": 0,
        "results": [
            "Installed: screen-4.6.2-10.el8.x86_64"
        ]
    }

    四,安装软件时关闭gpg验证

    #disable_gpg_check 值为yes时,禁用gpg验证

    [liuhongdi@centos8 ~]$ ansible yujian -m yum -a 'name=screen disable_gpg_check=yes' --become  --become-method=sudo --become-user=root

    说明:如果对应的 yum 源没有开启 gpg 验证,则需要将此参数的值设置为 yes,否则会报错而无法进行安装

            因为这里要和server交互

    五,安装软件时指定来源库

    #enablerepo 指定安装时的来源repo

    [liuhongdi@centos8 ~]$ ansible yujian -m yum -a 'name=screen enablerepo=epel' --become  --become-method=sudo --become-user=root

    六,查看centos的版本:

    [liuhongdi@centos8 ~]$ cat /etc/redhat-release 
    CentOS Linux release 8.1.1911 (Core)
  • 相关阅读:
    win10 uwp 弹起键盘不隐藏界面元素
    win10 uwp 存放网络图片到本地
    win10 uwp 存放网络图片到本地
    sublime Text 正则替换
    sublime Text 正则替换
    win10 uwp 绘图 Line 控件使用
    win10 uwp 绘图 Line 控件使用
    AJAX 是什么?
    什么是 PHP SimpleXML?
    PHP XML DOM:DOM 是什么?
  • 原文地址:https://www.cnblogs.com/architectforest/p/12755276.html
Copyright © 2011-2022 走看看