ansible、saltstack部署

//首先安装 :
yum install -y epel-release ##首先安装 epel源
yum install ansible -y

//查看版本(检查安装是否成功):
[root@localhost ~]# ansible --version

//主要配置文件:
[root@localhost ~]# tree /etc/ansible/ ##树状结构展示文件夹
/etc/ansible/
├── ansible.cfg ##ansible的配置文件
├── hosts ##ansible的主仓库,用于存储需要管理的远程主机的相关信息
└── roles ##角色

—管理端添加服务端:
[root@localhost ~]# cd /etc/ansible
[root@localhost ansible]# vim hosts
添加组名和对应的ip地址:
[组名]
ip
。。。
ip

1)关闭第一次使用ansible连接客户端时输入命令提示:

sed -i "s@\#host_key_checking = False@host_key_checking = False@g" /etc/ansible/ansible.cfg

指定日志路径:

sed -i "s@\#log_path = \/var\/log\/ansible.log@log_path = \/var\/log\/ansible.log@g" /etc/ansible/ansible.cfg

//配置密钥对验证:

ssh-keygen -t rsa	#master生成公钥
vim /etc/ansible/hosts  #添加被操控的主机ip
。。。

ansible all -m authorized_key -a “user=root key=‘{undefined{ lookup(‘file’, ‘/root/.ssh/id_rsa.pub’) }}’ path=/root/.ssh/authorized_keys manage_dir=no” --ask-pass -c paramiko #往host里面配置所有主机发送公钥


[root@localhost ansible]# ansible 组名 -m ping	#验证通信
10.0.0.32 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

#########成功------分割符############



ansible常用模块

Blockinfile模块:

```bash
在文件末尾插入两行
`[root@tiandong ~]# ansible all -m blockinfile -a "path=/tmp/rc.local block='service restart sshd\nservice restart httpd'`"

报错:
1.No module named ‘paramiko’ (centos20.04)

apt install python3-pip -y
pip install paramiko

ansible剧本技巧:地址

ansible异常:
1.check mode and async cannot be used on same task
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值