使用Ansible向被控节点配置yum源

笔者在使用ansible-playbook安装nginx的时候,发生没有找到对应的nginx包的错误,需要配置yum源;

使用ansible向被控节点配置yum源的原理是:首先控制主机安装yum源,然后将安装的yum源的文件拷贝到被控节点

环境:centos6.8,使用ansible-palybook安装Nginx为例

1.控制主机安装nginx需要的yum源

centos6 安装nginx的yum源:rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

2.配置yaml文件

ansible-playbook使用yaml文件完成安装。首先配置向被控节点安装nginx yum源(将控制主机的nginx.repo拷贝到被控节点);然后配置安装nginx。

yaml文件的tasks配置为:

tasks:
  - name: Copy Nginx yum source
    copy: src=/etc/yum.repos.d/nginx.repo dest=/etc/yum.repos.d/nginx.repo force=no 

  - name: Install Nginx Package
    yum: name=nginx state=present

其中“force=no”表示向被控节点拷贝文件时,当被控节点存在该文件则不拷贝。


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一个基本的Ansible Playbook来搭建单节点商城。您可以按照以下步骤进行操作: 1. 安装必要的软件包和依赖项:在Playbook中使用`yum`模块安装必要的软件包和依赖项。例如,您可能需要安装Apache、MySQL、PHP、Git等软件包。 2. 下载并配置商城代码和数据库:使用`git`模块从代码库中下载商城代码,并使用`mysql_db`模块创建数据库和用户,然后再将商城代码与数据库进行连接。 3. 配置Web服务器:使用`copy`模块将商城代码中的配置文件复制到正确的位置,并使用`service`模块启动Web服务器。 4. 配置防火墙:使用`firewalld`模块打开必要的口。例如,您可能需要打开HTTP和HTTPS口。 5. 配置SSL证书:使用`copy`模块将SSL证书复制到正确的位置,并使用`service`模块重新启动Web服务器。 这是一个基本的Ansible Playbook示例,用于搭建单节点商城。您可以根据您的需要进行更改和定制: ``` --- - name: Deploy eCommerce website hosts: webservers become: true vars: mysql_root_password: "password" tasks: - name: Install required packages yum: name: - httpd - mariadb-server - php - php-mysql - git state: latest - name: Start and enable Apache service: name: httpd state: started enabled: true - name: Start and enable MariaDB service: name: mariadb state: started enabled: true - name: Create MySQL database mysql_db: name: ecommerce state: present login_user: root login_password: "{{ mysql_root_password }}" - name: Create MySQL user mysql_user: name: ecommerce_user password: "password" priv: "ecommerce.*:ALL" state: present login_user: root login_password: "{{ mysql_root_password }}" - name: Download eCommerce code git: repo: https://github.com/ecommerce/ecommerce.git dest: /var/www/html - name: Copy configuration files copy: src: /path/to/config/files dest: /var/www/html/config - name: Start and enable firewall firewalld: service: http permanent: yes state: enabled - name: Copy SSL certificate copy: src: /path/to/cert dest: /etc/pki/tls/certs/ owner: root group: root mode: 0644 - name: Copy SSL key copy: src: /path/to/key dest: /etc/pki/tls/private/ owner: root group: root mode: 0600 - name: Restart Apache with SSL config service: name: httpd state: restarted ``` 请注意,在实际操作中,您需要将`webservers`替换为您想要部署商城的服务器的名称或IP地址。另外,您还需要替换`/path/to/config/files`、`/path/to/cert`和`/path/to/key`为您的配置文件、SSL证书和密钥的实际路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值