当前位置:   article > 正文

Ansible自动化部署及使用

ansible自动化部署

目录

一.部署Ansible服务部署

1.Ansible服务器配置域名解析

2.Ansible服务器部署

3.做ssh-key免密登录

二.Ansible基础配置

1.自定义主机清单

2.测试连通性

3.简洁输出

三.Inventory -主机清单

1.增加主机组

2.增加用户名和密码

3.更改端口

4.组的变量,子分组,自定义主机列表

四.Ad-Hoc-点对点模式

1.shell模块

2.复制模块

3.用户模块

4.软件包管理

5.服务模块

6.文件模块

7.收集模块

五.YAML非标记语言

六.Role

1.编写任务

2.准备配置文件

3.编写变量

4.编写处理程序

5.编写剧本

6.实施剧本


环境使用3台机器

Ansible主机:ip1

服务端主机01:ip2

服务端主机02:ip3

一.部署Ansible服务部署

1.Ansible服务器配置域名解析

  1. vim /etc/hosts
  2. ip1 ansible
  3. ip2 host1
  4. ip3 host2

2.Ansible服务器部署

  1. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  2. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  3. yum install -y epel-release
  4. yum install -y ansible
  5. rpm -qc ansible(查看配置文件,是否部署完成)
  6. /etc/ansible/ansible.cfg
  7. /etc/ansible/hosts

3.做ssh-key免密登录

  1. ssh-keygen
  2. ssh-copy-id ip

二.Ansible基础配置

1.自定义主机清单

  1. vim /etc/ansible/hosts
  2. host1
  3. host2

2.测试连通性

ansible   localhost   -m ping

3.简洁输出

ansible host1 -m ping  -o

三.Inventory -主机清单

1.增加主机组

  1. vim /etc/ansible/hosts
  2. [webserver]
  3. host1
  4. host2
ansible webserver -m ping –o

2.增加用户名和密码

  1. vim /etc/ansible/hosts
  2. [webserver]
  3. host[1:2] ansible_ssh_user='root' ansible_ssh_pass='密码'

3.更改端口


                
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/791002
推荐阅读
相关标签
  

闽ICP备14008679号