ansible一键化搭建本地YUM仓库

基础环境: CentOS6.9(2.6.32-696.el6.x86_64)+ansible(ansible-2.4.2.0-1.el6.noarch)

  • 编辑ansible的hosts文件

cat /etc/ansible/hosts

[yum_local]
10.0.0.168

  • 编写yum本地仓库搭建一键化剧本

- hosts: yum_local
tasks:
- name: 安装createrepo软件
yum: name=createrepo state=installed
- name: 安装Apache软件提供yum服务
yum: name=httpd state=installed
- name: 创建yum仓库目录
file: path=/data/yum_data state=directory owner=apache
- name: 创建yum仓库子目录一
file: path=/data/yum_data/centos/6/os/x86_64 state=directory owner=apache
- name: 创建yum仓库子目录二
file: path=/data/yum_data/epel/6/x86_64 state=directory owner=apache
- name: 创建yum仓库子目录三
file: path=/data/yum_data/centos/6/extras/x86_64 state=directory owner=apache
- name: 将项目需要的软件包同步到/data/yum_data/centos/6/os/x86_64目录
synchronize: src=/server/tools/packages/ dest=/data/yum_data/centos/6/os/x86_64 recursive=yes
- name: 初始化索引服务一
shell: createrepo --update /data/yum_data/centos/6/os/x86_64
- name: 初始化索引服务二
shell: createrepo --update /data/yum_data/epel/6/x86_64
- name: 初始化索引服务三
shell: createrepo --update /data/yum_data/centos/6/extras/x86_64
- name: yum仓库目录授权apahce用户管理
shell: chown -R apache.apache /data/yum_data/
- name: 修改httpd服务的主配置文件设置/data/yum_data/为网站的主目录一
lineinfile:
path: /etc/httpd/conf/httpd.conf
regexp: '^DocumentRoot \"\/var\/www\/html\"'
line: 'DocumentRoot "/data/yum_data/"'
backrefs: yes
backup: yes
- name: 修改httpd服务的主配置文件设置/data/yum_data/为网站的主目录二
lineinfile:
path: /etc/httpd/conf/httpd.conf
regexp: '^<Directory \"\/var\/www\/html\">'
line: '<Directory "/data/yum_data/">'
backrefs: yes
backup: yes
- name: 删除默认的页面/etc/httpd/conf.d/welcome.conf
file: path=/etc/httpd/conf.d/welcome.conf state=absent
- name: 开启httpd服务
service: name=httpd state=started enabled=yes

  • 搭建完成进行本地测试
    • 编辑主机的/etc/hosts文件进行域名解析设置

 

[root@m01 yum_local]# cat /etc/hosts
172.16.1.168 yum.shooter.com

 

    • 创建自己的本地安装的repo文件

 

[root@m01 yum_local]# cat /server/tools/localyum.repo
[localyum]
name=centos6
baseurl=http://yum.shooter.com/centos/6/os/x86_64/
enable=1
gpgcheck=0

 

[localepel]
name=epel
baseurl=http://yum.shooter.com/epel/6/x86_64/
enable=1
gpgcheck=0

 

[localextra]
name=extra
baseurl=http://yum.shooter.com/centos/6/extras/x86_64/
enable=1
gpgcheck=0

 

    • 进行本地yum安装测试

 

 

 

 

posted on 2018-04-11 09:03  吃胖了的包子  阅读(41)  评论(0)    收藏  举报