1

Ansible 如何在本机执行命令

 1 year ago
source link: https://www.lfhacks.com/tech/ansible-local-connection/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ansible 如何在本机执行命令

2022-05-28
阅读 1 分钟
1092.jpg
扫一扫,转发文章 ansible-local-connection.png

Ansible 用于在远程主机上执行命令,那么如果想在控制机上执行命令,该怎么配置?

Inventory 文件

Ansible 用 inventory 文件(/etc/ansible/hosts)规定受控主机。比如,想要规定 IP 地址为 10.1.2.3 的主机为一台受控主机,那么可以这么编辑 inventory 文件:

# inventoryworker ansible_host=10.1.2.3 ansible_user=someone

这样我们就能在 playbook 里面这么规定允许的主机:

# playbook.yaml- name: do something hosts: worker roles: - do_something

这样就指定了 playbook.yaml 仅在 10.1.2.3 这台主机上运行。

那么如果想在控制机本机上,也就是 ansible 运行的主机上执行命令,那么需要这么编写 inventory 文件:

local ansible_host=127.0.0.1 ansible_connection=local

需要指定连接方式 ansible_connection=local

  1. https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#non-ssh-connection-types

为了保证阅读体验,本站不安放广告。但是,租用服务器和编写文章需要资金和时间的投入。

如果您觉得文章对您有用,请考虑捐助小站(金额不限),以期待更多原创文章。

wechatpay.pngalipay.png
cc-by-nc.gif

若无特别说明,本站文章均为原创,并采用 署名协议 CC-BY-NC 授权。
欢迎转载,惟请保留原文链接,且不得用于商业用途。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK