ansible安装与部署
【ansible安装与部署】1.安装ansible
yum install ansible -y
2.管理被控端,管理机先生成秘钥,然后推送公钥
[root@demo ~]# ssh-keygen
[root@demo ~]# do ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.i;
done
3.配置被管理的主机清单
[root@demo ~]# vim /etc/ansible/hosts
[web]
10.0.0.100
10.0.0.200
4.使用ansible的ad-hoc测试
[root@demo ~]# ansible all -m ping
4.1 执行远程命令
[root@demo ~]# ansible all -m shell -a "df -h"
5.ansible playbook自动化安装nginx
注意前面的空格
[root@demo ~]# vim playbook_nginx.yml
- hosts: 主机组的名字
remote_user: root
vars:
http_port: 80
tasks:
- name: Add Nginx Yum Repository
yum_repository:
name: nginx
description: Nginx Repository
baseurl: http://nginx.org/packages/centos/7/$basearch/
gpgcheck: no
- name: Install Nginx Server
yum:
name=nginx state=present
- name: Configure Nginx Server
template: src=https://www.it610.com/article/default.conf.template dest=/etc/nginx/conf.d/default.conf
notify: Restart Nginx Server
- name: Start Nginx Server
service: name=nginx state=started enabled=yes
- name: Restart Nginx Server
service: name=nginx state=restarted
- name: Add Nginx Yum Repository
default.conf.template文件如下
[root@demo ~]#vim default.conf.template
server {
listen {{ http_port }};
server_name localhost;
location / {
root/usr/share/nginx/html;
indexindex.html index.htm;
}
}
7.执行ansible-playbook
检查语法
[root@demo ~]# ansible-playbook --syntax playbook_nginx.yml
模拟执行
[root@demo ~]# ansible-playbook -C playbook_nginx.yml
执行
[root@demo ~]# ansible-playbook playbook_nginx.yml
推荐阅读
- 汽车产业融资动态|C轮与C+轮累计融资超5亿美元,黑芝麻智能下一步要怎么走?
- CesiumJS|CesiumJS 更新日志 1.96 与 1.97 - 新构建工具 esbuild 体验及 Model API 更替完成
- 嵌入式软硬件|嵌入式软件组件经典架构与存储器分类
- 详聊immer.js高效复制与冻结"对象"的原理于局限性
- 中国已不缺少“马云”,而缺少更多的“袁隆平”与“唐国明”
- 目标是成功与否幸福与否的标准
- 葆婴事业与传统行业的区别()
- 云原生时代下,微服务体系与|云原生时代下,微服务体系与 Serverless 架构的发展、治理与融合
- Biostar|Biostar handbook学习笔记二—linux常用命令的学习与使用
- kali的安装与配置