如何在执行剧本时在命令行中添加多个清单文件 [英] How to add multiple inventory files in command line while executing a playbook

查看:23
本文介绍了如何在执行剧本时在命令行中添加多个清单文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本包含两种不同剧本的剧本

I am having a playbook with two different plays

Sample.yml
    - name : Play1
      hosts: Host1
      tasks:
       ...
    - name: Play2
      hosts: Host2
      tasks:
       ...

我需要用两个不同的主机(Host1 和 Host2)运行这个剧本,这两个不同的主机存在于两个不同的文件(Hostfile1 和 Hostfile2)中/目录.

I need to run this playbook with two different hosts(Host1 and Host2) and these two different hosts are present in two separate files(Hostfile1 and Hostfile2) under inventory/ directory.

inventory/
   Hostfile1
   Hostfile2
   .
   .
   HostfileN

我想知道如何在运行剧本时包含两个不同的主机文件.我知道通过在命令行中包含整个文件夹 (inventory/),我们可以实现这一点,但是我在inventory/文件夹中有很多主机文件,因此此选项将加载未使用的主机文件.

I want to know how to include two different hosts file while running the playbook. I know by including the entire folder (inventory/) in command line we can achieve this but I have lot of hosts files inside inventory/ folder so this option will load unused hosts file.

我试着像下面那样跑

ansible-playbook -i inventory/Hostfile1,Hostfile2 sample.yml

但这没有用.那么,有人知道如何通过在命令行中提供多个主机文件来运行剧本吗?

But this didn't work. So, do anyone know how to run the playbook by providing multiple hosts file in command line?

推荐答案

只需多次提供-i

ansible-playbook -iinventory/Hostfile1 -iinventory/Hostfile2 sample.yml

这篇关于如何在执行剧本时在命令行中添加多个清单文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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