gpt4 book ai didi

ansible - 如何在特定主机: ansible-playbook -i ,上运行ansible

转载 作者:行者123 更新时间:2023-12-05 01:10:39 25 4
gpt4 key购买 nike

The docs指定我可以使用 -i 在特定主机上运行我的剧本:

Patterns and ansible-playbook flags

You can change the behavior of the patterns defined in playbooks using command-line options. For example, you can run a playbook that defines hosts: all on a single host by specifying -i 127.0.0.2,. This works even if the host you target is not defined in your inventory. You can also limit the hosts you target on a particular run with the --limit flag:*

但是,我尝试运行 ansible-playbook <playbook> -i <new_hostname> -u <username>并且使用的库存仍然是我的默认库存。如何正确使用?

最佳答案

引自“man ansible”

-i, --inventory, --inventory-filespecify inventory host path or comma separated host list.

要将单个主机指定为“逗号分隔的主机列表”,仍然需要逗号。例如,剧本

shell> cat playbook.yml
- hosts: all
gather_facts: false
tasks:
- debug:
var: inventory_hostname

给予

shell> ansible-playbook -i test_99, playbook.yml

PLAY [all] ****

TASK [debug] ****
ok: [test_99] =>
inventory_hostname: test_99

主机后面没有逗号,Ansible 将参数作为“库存主机路径”。

shell> ansible-playbook -i test_99 playbook.yml
[WARNING]: Unable to parse /scratch/test_99 as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'

PLAY [all] ****
skipping: no hosts matched

关于ansible - 如何在特定主机: ansible-playbook -i <hostname>,上运行ansible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63944419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com