关于yum没有nginx源的问题 电脑版发表于:2021/4/3 15:59 问题 ------------ tn>现在像yum的阿里源,清华源与163源貌似都没有nginx的源,这就非常气人?所以我们只有自己添加了。 解决 ------------ ```bash cd /etc/yum.repos.d vim CentOS-Base.repo ``` ### Centos6 >在尾部添加如下内容 ```bash [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1 ``` ### Centos7 >在尾部添加如下内容 ```bash [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 ``` ### 最后更新 ```bash # 清缓存与更新 yum clean all yum makecache yum update # 安装 yum install nginx ``` 关于Ansible的替换脚本 ------------ tn>这里我只针对centos7,如果要做系统判断自己去写模版。 ```bash --- - hosts: all remote_user: root tasks: - name: 更换源 copy: src=/etc/yum.repos.d/CentOS-Base.repo dest=/etc/yum.repos.d/ notify: - clean mache - make mache - name: 更新源 shell: yum update -y handlers: - name: clean mache shell: yum clean all - name: make mache shell: yum makecache ``` tn>这里我们执行并来测试一下 ```bash ansible-playbook -C updateyum.yaml ansible-playbook updateyum.yaml ansible all -m shell -a 'cat /etc/yum.repos.d/CentOS-Base.repo' ``` ![](https://img.tnblog.net/arcimg/hb/3dfc335e149d4f659b9efec16344311a.png)