Ansible 不会创建 yum 存储库

Ansible 不会创建 yum 存储库

我正在尝试让 Ansible 在新的 AWS 实例上设置 EPEL 存储库。如果我使用该yum_repository模块,它会失败。如果我使用该yum模块并尝试通过网络安装它,它会报告成功,但实际上什么也没做。

yum_repository模块:

- name: Install EPEL
    yum_repository:
      name: epel
      description: EPEL YUM repo
      baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
    loop: "{{ ec2.instances }}"

Ansible 结果(红色):

TASK [Install EPEL] ****************************************************************************************************
failed: [localhost] (item={u'kernel': None, u'root_device_type': u'ebs', u'private_dns_name': u'ip-172-31-33-208.ec2.internal', u'public_ip': u'18.207.163.99', u'private_ip': u'172.31.33.208', u'id': u'i-0b05b63091e29d577', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'hvm', u'root_device_name': u'/dev/sda1', u'ramdisk': None, u'block_device_mapping': {u'/dev/sda1': {u'status': u'attached', u'delete_on_termination': False, u'volume_id': u'vol-04dbaef4c21d9879b'}}, u'key_name': u'AWSCentOS7', u'image_id': u'ami-4bf3d731', u'tenancy': u'default', u'groups': {u'sg-0f9a0c832c082129e': u'web'}, u'public_dns_name': u'ec2-18-207-163-99.compute-1.amazonaws.com', u'state_code': 16, u'tags': {}, u'placement': u'us-east-1a', u'ami_launch_index': u'0', u'dns_name': u'ec2-18-207-163-99.compute-1.amazonaws.com', u'region': u'us-east-1', u'launch_time': u'2018-06-02T18:44:05.000Z', u'instance_type': u't2.micro', u'architecture': u'x86_64', u'hypervisor': u'xen'}) => {"changed": false, "details": "[Errno 13] Permission denied: '/etc/yum.repos.d/epel.repo'", "item": {"ami_launch_index": "0", "architecture": "x86_64", "block_device_mapping": {"/dev/sda1": {"delete_on_termination": false, "status": "attached", "volume_id": "vol-04dbaef4c21d9879b"}}, "dns_name": "ec2-18-207-163-99.compute-1.amazonaws.com", "ebs_optimized": false, "groups": {"sg-0f9a0c832c082129e": "web"}, "hypervisor": "xen", "id": "i-0b05b63091e29d577", "image_id": "ami-4bf3d731", "instance_type": "t2.micro", "kernel": null, "key_name": "AWSCentOS7", "launch_time": "2018-06-02T18:44:05.000Z", "placement": "us-east-1a", "private_dns_name": "ip-172-31-33-208.ec2.internal", "private_ip": "172.31.33.208", "public_dns_name": "ec2-18-207-163-99.compute-1.amazonaws.com", "public_ip": "18.207.163.99", "ramdisk": null, "region": "us-east-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "tags": {}, "tenancy": "default", "virtualization_type": "hvm"}, "msg": "Cannot open repo file /etc/yum.repos.d/epel.repo."}

该长字符串中隐藏着错误:

"changed": false, "details": "[Errno 13] Permission denied: '/etc/yum.repos.d/epel.repo'"

消息如下:

msg": "Cannot open repo file /etc/yum.repos.d/epel.repo."}

错误是从我尝试使用becomebecome_user和的较长的字符串中提取的,become_method但这些没有帮助。

yum模块:

- name: Install EPEL
  yum:
    name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    state: present
  loop: "{{ ec2.instances }}"

- name: Import EPEL GPG Key
  rpm_key:
    key: /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    state: present
  loop: "{{ ec2.instances }}"

Ansible 结果(绿色):

TASK [Install EPEL] ********************************************************************************************************************
ok: [localhost] => (item={u'kernel': None, u'root_device_type': u'ebs', u'private_dns_name': u'ip-172-31-40-128.ec2.internal', u'public_ip': u'54.211.185.153', u'private_ip': u'172.31.40.128', u'id': u'i-00df2781d264e5da7', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'hvm', u'root_device_name': u'/dev/sda1', u'ramdisk': None, u'block_device_mapping': {u'/dev/sda1': {u'status': u'attached', u'delete_on_termination': False, u'volume_id': u'vol-0d6444601bbfcbe15'}}, u'key_name': u'AWSCentOS7', u'image_id': u'ami-4bf3d731', u'tenancy': u'default', u'groups': {u'sg-0f9a0c832c082129e': u'web'}, u'public_dns_name': u'ec2-54-211-185-153.compute-1.amazonaws.com', u'state_code': 16, u'tags': {}, u'placement': u'us-east-1a', u'ami_launch_index': u'0', u'dns_name': u'ec2-54-211-185-153.compute-1.amazonaws.com', u'region': u'us-east-1', u'launch_time': u'2018-06-02T19:22:40.000Z', u'instance_type': u't2.micro', u'architecture': u'x86_64', u'hypervisor': u'xen'})

TASK [Import EPEL GPG Key] *************************************************************************************************************
ok: [localhost] => (item={u'kernel': None, u'root_device_type': u'ebs', u'private_dns_name': u'ip-172-31-40-128.ec2.internal', u'public_ip': u'54.211.185.153', u'private_ip': u'172.31.40.128', u'id': u'i-00df2781d264e5da7', u'ebs_optimized': False, u'state': u'running', u'virtualization_type': u'hvm', u'root_device_name': u'/dev/sda1', u'ramdisk': None, u'block_device_mapping': {u'/dev/sda1': {u'status': u'attached', u'delete_on_termination': False, u'volume_id': u'vol-0d6444601bbfcbe15'}}, u'key_name': u'AWSCentOS7', u'image_id': u'ami-4bf3d731', u'tenancy': u'default', u'groups': {u'sg-0f9a0c832c082129e': u'web'}, u'public_dns_name': u'ec2-54-211-185-153.compute-1.amazonaws.com', u'state_code': 16, u'tags': {}, u'placement': u'us-east-1a', u'ami_launch_index': u'0', u'dns_name': u'ec2-54-211-185-153.compute-1.amazonaws.com', u'region': u'us-east-1', u'launch_time': u'2018-06-02T19:22:40.000Z', u'instance_type': u't2.micro', u'architecture': u'x86_64', u'hypervisor': u'xen'})

实例结果:

[centos@ip-###-###-###-### ~]$ rpm -qa |grep -i epel
[centos@ip-###-###-###-### ~]$

如何设置存储库?

答案1

循环并不像您想象的那样工作。

您的剧本使用了错误的hosts,也就是说您正在针对本地主机运行 yum_repository。

您应该将hosts剧本中的 var 设置为您拥有的 aws 实例。

相关内容