playbook实现不同系统yum仓库配置
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了playbook实现不同系统yum仓库配置,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5598字,纯文字阅读大概需要8分钟。
内容图文
![playbook实现不同系统yum仓库配置](/upload/InfoBanner/zyjiaocheng/930/fa63c30e319348f49667024b5dbbb8d8.jpg)
playbook实现不同系统yum仓库配置
环境介绍
ip地址 | 系统和版本号 | 名称 |
---|---|---|
192.168.102.134 | ansible主控机 | cst |
192.168.102.140 | CentOS7 | c7 |
192.168.102.141 | CentOS8 | c8 |
192.168.102.142 | RedHat7 | r7 |
192.168.102.143 | RedHat8 | r8 |
配置主控机
//创建项目
[root@cst ~]# yum -y install ansible
[root@cst ~]# mkdir myrepo
[root@cst ~]# cd myrepo
[root@cst myrepo]# cp /etc/ansible/ansible.cfg .
[root@cst ~]# vim /etc/ansible/ansible.cfg
inventory = /etc/ansible/inventory
//为其主机写映射,方便操作
[root@cst ~]# vim /etc/hosts
192.168.102.140 c7
192.168.102.141 c8
192.168.102.142 r7
192.168.102.143 r8
//配置清单文件
[root@cst myrepo]# vim inventory
c7
c8
r7
r8
//为其他主机做ssh连接
[root@cst myrepo]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:FgrLx7dWSGIrz2KAlNH4VgVIHXjGncx3B1NXgqpbkEw root@cst
The key's randomart image is:
+---[RSA 3072]----+
| .+.=oB.. ooo..o|
| .o+ * =E. .o... |
| o. = oo+.... |
|.. + = =+o. |
|. o + = So. |
| . = o.o. |
| o o oo |
| . . .. |
| |
+----[SHA256]-----+
[root@cst myrepo]# ssh-copy-id root@c7
[root@cst myrepo]# ssh-copy-id root@c8
[root@cst myrepo]# ssh-copy-id root@r7
[root@cst myrepo]# ssh-copy-id root@r8
[root@cst myrepo]# ansible all -m ping
c7 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
c8 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
r7 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
r8 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
编写playbook
[root@cst myrepo]# vim repo.yml
---
- hosts: all
vars:
baseurl_8: https://mirrors.aliyun.com/epel/8/Modular/x86_64/
baseurl_7: https://mirrors.aliyun.com/epel/7/x86_64/
tasks:
- name: yum config for 8
yum_repository:
name: "{{ item }}"
baseurl: https://mirrors.aliyun.com/centos/8/{{ item }}/x86_64/os/
enabled: yes
gpgcheck: no
mode: 0644
file: "{{ item }}"
description: "{{ item }}"
state: present
loop:
- BaseOS
- AppStream
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: yum config for 7
yum_repository:
name: base
baseurl: https://mirrors.aliyun.com/centos/7/os/x86_64/
enabled: yes
gpgcheck: no
mode: 0644
file: base
description: base
state: present
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: yum config epel for 8
yum_repository:
name: epel
baseurl: "{{ baseurl_8 }}"
enabled: yes
gpgcheck: no
mode: 0644
file: epel
description: epel
state: present
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: yum config epel for 7
yum_repository:
name: epel
baseurl: "{{ baseurl_7 }}"
enabled: yes
gpgcheck: no
mode: 0644
file: epel
description: epel
state: present
when: >
( ansible_facts["distribution"] == "RedHat" and
ansible_facts["distribution_major_version"] == "7" )
or
( ansible_facts["distribution"] == "CentOS" and
ansible_facts["distribution_major_version"] == "7" )
执行并查看结果
[root@cst myrepo]# ansible-playbook repo.yml
[root@c7 ~]# yum repolist
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
[root@c8 ~]# yum repolist
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
[root@r7 ~]# yum repolist
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
[root@r8 ~]# yum repolist
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
内容总结
以上是互联网集市为您收集整理的playbook实现不同系统yum仓库配置全部内容,希望文章能够帮你解决playbook实现不同系统yum仓库配置所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。