首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ansible load epel和yum update

Ansible load epel和yum update
EN

Stack Overflow用户
提问于 2020-05-24 05:16:35
回答 3查看 1.6K关注 0票数 0

尝试添加epel,然后在amazon-linux-2服务器上通过ansible执行yum更新。我使用的URL基于:https://aws.amazon.com/premiumsupport/knowledge-center/ec2-enable-epel/

我的ansible脚本是:

代码语言:javascript
运行
复制
---
- hosts: all
  remote_user: cloud_user

  tasks:

  - name: 01 add epel
    yum_repository:
      name: epel
      description: EPEL YUM repo
      baseurl: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    become: yes

  - name: 02 yum update 
    yum: name=* state=latest
    become: yes

我在任务02上的错误是(任务01有一个“更改”的通知):

代码语言:javascript
运行
复制
     FAILED! => {"changed": false, "msg": "https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm/repodata/repomd.xml: 
[Errno 14] HTTPS Error 404 - Not Found\nTrying other mirror.\n\n\n One of the configured repositories failed (EPEL YUM repo),\n and yum doesn't have enough cached data to continue. At this point the only\n safe thing yum can do is fail. There are a few ways to work \"fix\" this:\n\n     
1. Contact the upstream for the repository and get them to fix the problem.\n\n     
2. Reconfigure the baseurl/etc. for the repository, to point to a working\n        upstream. This is most often useful if you are using a newer\n        distribution release than is supported by the repository (and the\n        packages for the previous distribution release still work).\n\n     
3. Run the command with the repository temporarily disabled\n            yum --disablerepo=epel ...\n\n     
4. Disable the repository permanently, so yum won't use it by default. Yum\n        
will then just ignore the repository until you permanently enable it\n        again or use --enablerepo for temporary usage:\n\n            
yum-config-manager --disable epel\n        
or\n            
subscription-manager repos --disable=epel\n\n     
5. Configure the failing repository to be skipped, if it is unavailable.\n        Note that yum will try to contact the repo. when it runs most commands,\n        
so will have to try and fail each time (and thus. yum will be be much\n        
slower). If it is a very temporary problem though, this is often a nice\n        
compromise:\n\n            yum-config-manager --save --setopt=epel.skip_if_unavailable=true\n\nfailure: repodata/repomd.xml from epel:
 [Errno 256] No more mirrors to try.\nhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm/repodata/repomd.xml: 
[Errno 14] HTTPS Error 404 - Not Found\n", "rc": 1, "results": []}

任何指导或帮助都是很棒的。

EN

回答 3

Stack Overflow用户

发布于 2020-05-24 05:57:00

https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm不是yum存储库,它是一个yum包。

正如您在所链接的文档中所看到的,他们对其进行了yum install

代码语言:javascript
运行
复制
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

然后,他们通过命令yum-config-manager启用它

代码语言:javascript
运行
复制
sudo yum-config-manager --enable epel

另一方面,https://dl.fedoraproject.org/pub/epel/$releasever/$basearch/是一个yum存储库URL。

所以你的第一个任务应该是

代码语言:javascript
运行
复制
- name: 01 add epel
    yum_repository:
      name: epel
      description: EPEL YUM repo
      baseurl: https://dl.fedoraproject.org/pub/epel/$releasever/$basearch/
    become: yes

你的错误实际上说明了这一点:

https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm/repodata/repomd.xml

查看它如何尝试获取文件夹repodata和文件repomd.xml

现在,如果您浏览https://dl.fedoraproject.org/pub/epel/并查看文件夹7,然后在任何子文件夹下,您将找到确切的repodata文件夹和确切的repomd.xml文件。

注意:可以找到有关变量$releasever$basearch的额外信息:

此外,由于您的知识文章指导您使用版本7(请参阅epel-release-latest-7.noarch.rpm中的7),因此您可以做的是将其作为属性传递给yum任务。

代码语言:javascript
运行
复制
- name: 02 yum update 
  yum: 
    name: '*' 
    state: latest
    releasever: 7
  become: yes

注意:我还改变了你的语法,我想说在同一本剧本中混合使用attribute=value和YAML语法是一个坏主意。

票数 1
EN

Stack Overflow用户

发布于 2020-05-25 11:32:55

要安装EPEL,只需从基础存储库安装epel-release包就足够了。此外,考虑到建议尽可能不使用shellcommand模块,我们可以通过直接更新配置文件来启用存储库。因此,我会提出以下建议:

代码语言:javascript
运行
复制
- name: Install EPEL repository
  yum:
    name: epel-release
    state: present

- name: Ensure EPEL repo is enabled
  ini_file:
    dest: /etc/yum.repos.d/epel.repo
    section: epel
    option: enabled
    value: '1'

- name: Conduct yum update 
  yum: 
    name: * 
    state: latest
    become: True
    update_cache: True
票数 0
EN

Stack Overflow用户

发布于 2020-05-30 05:52:40

感谢您的所有投入。不确定这是否是amazon-linux-2的东西,但我得到的唯一一个是使用galaxy角色,代码如下:

代码语言:javascript
运行
复制
  roles:
    - role: geerlingguy.repo-epel
      vars:
        epel_repo_url: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
        epel_repo_gpg_key_url: "/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7"
      become: yes
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61978672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档