翼度科技»论坛 云主机 LINUX 查看内容

ansible入门指南 - 安装与简单使用

1

主题

1

帖子

3

积分

新手上路

Rank: 1

积分
3
ansible 是用来自动化管理远程操作系统的工具.
ansible的三要素: 控制节点 , 被控节点, 资产清单
安装

ansible 可以通过pip直接安装
  1. python3 -m pip install ansible --user
复制代码
快速入门

创建inventory文件, 把需要管理的机器登记在该文件中, 此处假装有两台被控机器, 划分在group1组中
  1. echo -e '[group1]\n127.0.0.1\nlocalhost' > inventory
复制代码
配置免密登录主机, 根据提示输入密码
  1. ssh-copy-id chino@127.0.0.1
  2. ssh-copy-id chino@localhost
复制代码
检查inventory的所有主机. 此处的all表示选中所有主机, 如果inventory文件中, 被控机器划分在不同的组中, 也可以使用组名 / 主机IP地址 替代all
  1. ansible -i inventory all --list-hosts
  2. # 看到以下输出表示配置成功
  3. #  hosts (3):
  4. #    127.0.0.1
  5. #    localhost
复制代码
检查group1中的主机是否在线, inventory即我们上面新建的主机清单文件
  1. ansible -i inventory group1 -m ping
  2. # 没问题的话将会输出以下结果
  3. 127.0.0.1 | SUCCESS => {
  4.     "changed": false,
  5.     "ping": "pong"
  6. }
  7. localhost | SUCCESS => {
  8.     "ansible_facts": {
  9.         "discovered_interpreter_python": "/usr/bin/python3"
  10.     },
  11.     "changed": false,
  12.     "ping": "pong"
  13. }
复制代码
-m ping指调用使用ansible的ping模块, 后面的文章会介绍模块的用法

来源:https://www.cnblogs.com/Chinori/p/17640751.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具