ansible部署apache

ansible部署apache

安装ansble

Ansible 包不在 CentOS 8 默认的软件包仓库中。因此,我们需要执行以下命令启用 EPEL 仓库
yum  install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
启用 epel 仓库后,执行以下 dnf 命令安装 Ansible:
yum install -y ansible* 
2.配置HOSTS 每个节点都配置
master192.168.1.11
node02192.168.1.23
[root@master /]# vim /etc/hosts 
192.168.1.11 master
192.168.1.23 node02
3.配置单向免密登录 只在管理节点进行操作 并测试
ssh-keygen 
ssh-copy-id root@192.168.1.23 
scp /etc/hosts root@192.168.1.23                         #复制hosts文件到客户端 
将/etc/ansible/* 文件复制到家目录
 cp -a /etc/ansinle  /home/用户/            
5.修改配置文件
[root@master /]# vim /home/whd/ansible/ansible.cfg 
inventory      = /home/whd/ansible/hosts
# 配置主机清单
[root@master /]# vim /home/whd/ansible/hosts 
[server]
root@192.168.1.11

[node]
192.168.1.23
验证
[root@master ansible]# ansible all -m ping
root@192.168.1.11 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: root@192.168.1.11: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
    "unreachable": true
}
192.168.1.23 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
# 出现错误 ,客户端主机权限拒绝 
# 解决方法 
[root@master ansible]# ansible all -m ping --ask-pass --ask-become-pass   #加入 --ask-pass --ask-become-pass
root@192.168.1.11 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.1.23 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
#ok 

编写apache yaml文件

[root@master ansible]# vim apache.yaml
---
- name:
  hosts: server
  tasks:
    - name: install httpd server
      yum:
        name: httpd*
        state: present

    - name: start httpd
      service:
        name: httpd
        state: started
        enabled: yes

    - name: isstall php
      yum:
        name: php*
        name: php-fpm*
        state: present

    - name: start php-fpm
      service:
        name: php-fpm
        state: started
        enabled: yes

##  执行yaml文件 
~~~3
[root@master ansible]# ansible-playbook apache.yaml 
[WARNING]: While constructing a mapping from /home/whd/ansible/apache.yaml, line 18, column 9, found a
duplicate dict key (name). Using last defined value only.

PLAY [server] ********************************************************************************************

TASK [Gathering Facts] ***********************************************************************************
ok: [root@192.168.1.11]

TASK [install httpd server] ******************************************************************************
ok: [root@192.168.1.11]

TASK [start httpd] ***************************************************************************************
ok: [root@192.168.1.11]

TASK [isstall php] ***************************************************************************************
ok: [root@192.168.1.11]

TASK [start php-fpm] *************************************************************************************
ok: [root@192.168.1.11]

PLAY RECAP ***********************************************************************************************

结果

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值