Ansible — 部署

    Ansible基于Python开发,集合了众多优秀运维工具的优点,实现了批量运行命令、部署程序、配置系统等功能。默认通过SSH协议进行远程命令执行或下发配置,无需任何客户端代理软件,从而使得自动化环境部署变得简单,同时支持多台主机并行管理,使得管理主机更加便携。

一、部署

1、配置yum源

    # wget http://mirrors.aliyun.com/repo/Centos-7.repo 
    # wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

2、安装软件

# yum install epel-release -y
# yum repolist
# yum install ansible -y
# yum install tree -y

3、查看配置文件结构

# tree /etc/ansible/

4、配置主机清单

# vim /etc/ansible/hosts 
        [webserver]           # 主机分类组名
        192.168.11.196        # 被管服务器
        
        [test]
        name1     ansible_ssh_host=192.168.1.111   ansible_ssh_user="root"   ansible_ssh_pass="1234"    ansible_ssh_port=22

# ansible webserver --list-hosts

5、生成秘钥对

# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.11.196
或者
# ansible  webserver -m shell -a 'ls' -k           # 交互输入远程机器密码,会保存在/root/.ssh/known_hosts中

6、列出所有安装模块

# ansible-doc -l (q退出)

7、列出user模块描述信息和操作动作

# ansible-doc -s user

8、command模块命令格式

# ansible  主机分类组名/all -m(指定模块)  模块名   -a(命令参数)   'uptime'
# ansible 192.168.11.196 -m command(默认模块)  -a 'date'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay_Fred

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值