文件查詢

  1. yum 模組可以做套件管理,完整文件可用 ansible-doc 查詢 yum 模組文件。
    [deyu1@kvm19 ansible]$ ansible-doc yum | grep ^EX -A10
    EXAMPLES:
    
    - name: Install the latest version of Apache
      ansible.builtin.yum:
        name: httpd
        state: latest
    
    - name: Install Apache >= 2.4
      ansible.builtin.yum:
        name: httpd>=2.4
        state: present
    
  2. 確認 dev 群組裡所有主機,套件 vim 還沒安裝,回傳成功。
    [deyu1@kvm19 ansible]$ ansible dev -m yum -a "name=vim state=absent"
    kvm11 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python3"
        },
        "changed": false,
        "msg": "Nothing to do",
        "rc": 0,
        "results": []
    }
    
  3. 使用 yum 模組安裝 vim 至最新版本,回傳成功,含相依套件共安裝了 4 的套件。
    [deyu1@kvm19 ansible]$ ansible dev -m yum -a "name=vim state=latest"
    kvm11 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python3"
        },
        "changed": true,
        "msg": "",
        "rc": 0,
        "results": [
            "Installed: vim-common-2:8.2.2637-16.el9_0.3.x86_64",
            "Installed: vim-enhanced-2:8.2.2637-16.el9_0.3.x86_64",
            "Installed: vim-filesystem-2:8.2.2637-16.el9_0.3.noarch",
            "Installed: gpm-libs-1.20.7-29.el9.x86_64"
        ]
    }