惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Last Week in AI
Last Week in AI
月光博客
月光博客
D
DataBreaches.Net
WordPress大学
WordPress大学
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
C
Check Point Blog
F
Fortinet All Blogs
B
Blog
小众软件
小众软件
Vercel News
Vercel News
罗磊的独立博客
有赞技术团队
有赞技术团队

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟
ansible使用笔记
2016-01-14 · via 夜行人

手头的服务器越来越多,下决心好好学学ansible了

#本机安装 使用本地机器(mac)作为控制端

pip install ansible

#加入被控机器

以青云上的两台服务器为例(ubuntu12.04 64bit),地址分别为:

  • 209.9.106.126 (insight)
  • 207.226.143.91 (cypress)

以及内网的一台机器:

  • 10.10.100.114 (gogs)

vim Inventory

1
2
3
4
5
6
7
8
[insight]
insight 209.9.106.126 ansible_connection=ssh  ansible_ssh_user=ubuntu

[cypress]
cypress 207.226.143.91  ansible_connection=ssh  ansible_ssh_user=ubuntu

[gogs]
10.10.100.114 ansible_connection=ssh  ansible_ssh_user=ubuntu

###ssh免密码配置 最简单的方式是:ssh-copy-id -i ~/.ssh/id_rsa.pub 209.9.106.126

###跑跑看 ansible -i Inventory all -m ping (以下为输出)

1
2
3
4
5
6
7
8
9
:::text
insight | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
cypress | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

#默认配置 vim ~/.ansible.cfg

1
2
3
# .ansible.cfg
[defaults]
hostfile=~/ansible_workplace/Inventory

之后就可以不用-i了

###给受控机器添加SSH authorized key 批量配置authorized key的话,使用核心模块authorized_key_module

ansible -i Inventory insight -m authorized_key -a “user=ubuntu key=https://github.com/wwj718.keys” #使用核心模块-m authorized_key,使用Ad-hoc(快速运行)

#随便做些探索 ansible cypress -a “ls ~” ansible insight -a “ls ~” ansible all -a “ls ~”

###copy file(local => remote) echo “#hello ansible copy” > /tmp/hello.py ansible all -m copy -a “src=/tmp/hello.py dest=/tmp” ansible all -a “cat /tmp/hello.py”

以下为输出:

1
2
3
4
5
6
:::text
cypress | SUCCESS | rc=0 >>
#hello ansible copy

insight | SUCCESS | rc=0 >>
#hello ansible copy

###安装软件包 ansible gogs -m apt -a ’name=nethogs’ -u wwj718 –sudo -K

#资源

#参考资料

文章作者 种瓜

上次更新 2016-01-14