如何在不指定清单但直接指定主机的情况下运行 Ansible? [英] How to run Ansible without specifying the inventory but the host directly?

查看:40
本文介绍了如何在不指定清单但直接指定主机的情况下运行 Ansible?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Python 中运行 Ansible 而不通过 (ANSIBLE_HOST) 指定库存文件,而只是通过:

I want to run Ansible in Python without specifying the inventory file through (ANSIBLE_HOST) but just by:

ansible.run.Runner(
  module_name='ping',
  host='www.google.com'
)

我实际上可以轻松地在 fabric 中做到这一点,但只是想知道如何在 Python 中做到这一点.另一方面,Ansible API for python 的文档并不完整.

I can actually do this in fabric easily but just wonder how to do this in Python. On the other hand, documentation of the Ansible API for python is not really complete.

推荐答案

出人意料的是,诀窍是附加一个 ,

Surprisingly, the trick is to append a ,

# Host and IP address
ansible all -i example.com,
ansible all -i 93.184.216.119,

# Requires 'hosts: all' in your playbook
ansible-playbook -i example.com, playbook.yml

, 前面的主机参数可以是主机名或 IPv4/v6 地址.

The host parameter preceding the , can be either a hostname or an IPv4/v6 address.

这篇关于如何在不指定清单但直接指定主机的情况下运行 Ansible?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆