标签:CentOS com 配置 repo yum playbook root localhost
主机 | ip | 系统 |
---|---|---|
localhost | 192.168.122.134 | rhel8 |
cb2 | 192.168.122.137 | centos7 |
cb3 | 192.168.122.138 | rhel8 |
结构树
[root@localhost ~]# tree . . ├── anaconda-ks.cfg └── yum ├── ansible.cfg ├── inventory ├── scripts │ ├── centos6.sh │ ├── centos7.sh │ └── centos8.sh └── yum.yml
准备环境
[root@localhost ~]# mkdir yum [root@localhost ~]# mkdir yum/scripts [root@localhost yum]# cp /etc/ansible/ansible.cfg . [root@localhost yum]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.122.137 cb2 192.168.122.138 cb3 [root@localhost yum]# vim ansible.cfg inventory = ./inventory [root@localhost yum]# vim inventory [centos] cb2 [redhat] cb3 [root@localhost ~]# ssh-keygen -t rsa [root@localhost ~]# ssh-copy-id root@192.168.122.137 [root@localhost ~]# ssh-copy-id root@192.168.122.138
配置脚本
//编写centos8脚本 [root@localhost ~]# vim yum/scripts/centos8.sh #!/bin/bash mount /dev/cdrom /mnt # CentOS 8 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo sed -i 's|$releasever|8|' /etc/yum.repos.d/CentOS-Base.repo # epel 8 yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* yum clean all && yum makecache //编写centos7脚本 [root@localhost ~]# vim yum/scripts/centos7.sh #!/bin/bash mount /dev/cdrom /mnt # CentOS 7 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo sed -i 's|$releasever|7|' /etc/yum.repos.d/CentOS-Base.repo # epel 7 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo sed -i 's|$releasever|7|' /etc/yum.repos.d/epel* yum clean all && yum makecache //编写centos6脚本 [root@localhost ~]# vim yum/scripts/centos6.sh #!/bin/bash mount /dev/cdrom /mnt # CentOS 6 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo sed -i 's|$releasever|6|' /etc/yum.repos.d/CentOS-Base.repo # epel 6 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo sed -i 's|$releasever|6|' /etc/yum.repos.d/epel* yum clean all && yum makecache
编写yum的playbook
[root@localhost ~]# vim yum/yum.yml --- - name: yum hosts: all tasks: - name: centos8 script: ./scripts/centos8.sh when: > ( ansible_facts["distribution"] == "RedHat" and ansible_facts["distribution_major_version"] == "8" ) or ( ansible_facts["distribution"] == "CentOS" and ansible_facts["distribution_major_version"] == "8" ) - name: centos7 script: ./scripts/centos7.sh when: > ( ansible_facts["distribution"] == "RedHat" and ansible_facts["distribution_major_version"] == "7" ) or ( ansible_facts["distribution"] == "CentOS" and ansible_facts["distribution_major_version"] == "7" ) - name: centos6 script: ./scripts/centos6.sh when: > ( ansible_facts["distribution"] == "RedHat" and ansible_facts["distribution_major_version"] == "6" ) or ( ansible_facts["distribution"] == "CentOS" and ansible_facts["distribution_major_version"] == "6" )
运行
[root@localhost ~]# cd yum/ [root@localhost yum]# ansible-playbook yum.yml
验证
//centos8 [root@cb2 ~]# yum repolist Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. repo id repo name AppStream CentOS-8 - AppStream - mirrors.aliyun.com base CentOS-8 - Base - mirrors.aliyun.com epel Extra Packages for Enterprise Linux 8 - x86_64 epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64 extras CentOS-8 - Extras - mirrors.aliyun.com //centos7 [root@cb3 ~]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status base/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,492 extras/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 448 updates/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,155 repolist: 25,167
标签:CentOS,com,配置,repo,yum,playbook,root,localhost 来源: https://www.cnblogs.com/cbcbage/p/14276604.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。