From 98d0b8f52dd382fa98502aa1acb2a5e760b681d1 Mon Sep 17 00:00:00 2001 From: jaywcjlove Date: Sun, 6 Nov 2022 12:52:53 +0000 Subject: [PATCH] feat: add ansible cheatsheet. (#23) d1dea833309c3f81f05a24d5f3ee97bc37710166 --- docs/ansible.html | 169 ++++++++++++++++++++++++++++++++++++++++++++++ index.html | 5 +- 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 docs/ansible.html diff --git a/docs/ansible.html b/docs/ansible.html new file mode 100644 index 00000000..0968214d --- /dev/null +++ b/docs/ansible.html @@ -0,0 +1,169 @@ + + + + +Ansible 备忘清单 + & ansible cheatsheet & Quick Reference + + + + + + + +

+ +Ansible 备忘清单

+

此快速参考备忘单提供了使用 Ansible 的各种方法。

+

入门

+

安装

+ + + + + + + + + + + + + + + + + + + + + +
安装命令环境
brew install ansiblemacos
yum install -y ansiblecentos
pip install ansiblepython
+

配置位置

+ + + + + + + + + + + + + + + + + + + + + +
文件路径说明
/etc/ansible/ansible.cfg系统范围的配置
~/ansible.cfg用户特定的配置
$pwd/ansible.cfg当前目录下的配置
+

Inventory文件(hosts列表)

+

静态Inventory

+

/etc/ansible/hosts

+
mail.example.com
+
+[webservers]
+foo.example.com
+bar.example.com
+
+

命令行(ad-hoc)

+

ansible

+

检查Inventory是否生效

+
ansible all --list-hosts
+
+

ping所有目标

+
$ ansible all -m ping
+
+

ping本地(不使用SSH连接)

+
$ ansible all -i localhost, -e '{"ansible_connection": "local"}' -m ping
+
+ +

本地执行命令

+
$ ansible all -i localhost, -e '{"ansible_connection": "local"}' -a 'hostname'
+
+ +

获取本地主机的信息

+
$ ansible all -i localhost, -e '{"ansible_connection": "local"}' -m setup
+
+ +

获取远程到本地

+
$ ansible target -m fetch -a "src=/tmp/seq dest=/tmp/seq"
+
+ +

拷贝本地到远程

+
$ ansible target -m copy -a "src=/tmp/seq dest=/tmp/seq"
+
+ + + +
+ diff --git a/index.html b/index.html index 00433d3e..e191fe2e 100644 --- a/index.html +++ b/index.html @@ -310,7 +310,10 @@ SSH -Screen

+Screen + + +Ansible

其它