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

查看:500
本文介绍了如何在不指定清单但直接指定主机的情况下运行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中执行此操作.另一方面,用于Python的Ansible API的文档还不是很完整.

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

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

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

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

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