在 Ansible 运行 之后找不到 epel-release

epel-release not found after Ansible run

我正在开发我的第一本剧本。我正在使用 3 个 CentOS 8 虚拟机。在我的本地电脑上使用 Oracle Virtual Box Windows 10,它虚拟化了一个 Ansible 控制器 VM 和 2 个目标 VM。

我的inventory.txt:

# Inventory File
target1 ansible_ssh_pass=osboxes.org ansible_host=192.168.1.106
target2 ansible_ssh_pass=osboxes.org ansible_host=192.168.1.153

我的剧本-webapp.yaml 包含:

# Ansible Playbook to install a web application

-
 name: Deploy Web application
 hosts: target1, target2
 remote_user: root
 tasks:
     - name: Install dependencies
       yum: name= {{ item }} state=installed
       with_items:
         - epel-release
         - python
         - python-pi

我执行:

ansible-playbook playbook-webapp.yaml -i inventory.txt

输出:

PLAY [Deploy Web application] *********************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************
ok: [target2]
ok: [target1]

TASK [Install dependencies] ***********************************************************************************************************************
ok: [target1] => (item=epel-release)
ok: [target2] => (item=epel-release)
ok: [target1] => (item=python)
ok: [target2] => (item=python)
ok: [target1] => (item=python-pip)
ok: [target2] => (item=python-pip)

PLAY RECAP ****************************************************************************************************************************************
target1                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
target2                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

但是当我尝试检查 target1 节点上的 yum 存储库时:

[osboxes@target1 ~]$ yum repolist
repo id                         repo name
appstream                       CentOS Linux 8 - AppStream
baseos                          CentOS Linux 8 - BaseOS
extras                          CentOS Linux 8 - Extras

但是,没有显示某种 epel-release,而是在要安装的 ansible 任务中设置。

如果我尝试执行

[osboxes@ansiblecontroller web_deployment]$ ansible all -m ping -i inventory.txt

输出:

target2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
target1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"

欢迎任何建议。

尝试使用 dnf module:

安装包
- name: Install dependencies
  dnf:
    name:
      - epel-release
      - python
      - python-pi

此外,使用 Ansible 管理系统的一个好方法是下载操作系统,安装 python3,然后再次打包您的系统并将打包的 OS 用于所有 VM。这样,系统尽可能 'bald',但只包含 python3,这对 Ansible 使用有好处。

no epel-release or other is shown

这其实很奇怪。这听起来像是你应该追求的东西。由于我们不知道这里的背景细节,我只能猜测并指导你正确的方向。

我想问 myself/you 您是否有 'targetted' 正确的机器。有 100 种方法可以验证是否是这种情况。我会这样做:

- shell: touch /tmp/hi

然后登录系统,检查/tmp/hi是否存在...如果存在,则说明有问题。

检查已安装的软件包:

rpm -qa | grep -i epel

安装了吗?

此外,yum.repos.d 应该包含 epel 存储库文件

[vagrant@vm-local-1 ~]$ ls /etc/yum.repos.d/ | grep epel
epel-modular.repo
epel-playground.repo
epel-testing-modular.repo
epel-testing.repo
epel.repo

请告诉我们。

按照@Kevin 的建议,正确的剧本是:

# Ansible Playbook to install a web application

-
 name: Deploy Web application
 hosts: target1, target2
 remote_user: root
 tasks:
     - name: Install dependencies
       dnf:
        name:
         - epel-release
         - python3
         - python3-pip
        state: installed 

检查目标虚拟机:

 yum repolist

ls /etc/yum.repos.d/ | grep epel

python3 --version