如何在Ansible中将主机指定为变量?配置后执行报错求助
Ansible 动态指定主机执行 playbook 失败问题
网上找了不少相关示例,但都解决不了我的问题,具体情况如下:
情况1:通过变量指定目标主机
我的 test.yaml 内容如下:
--- - hosts: "{{ non_default_host }}" tasks: - debug: msg: 'This is the host specified'
执行以下命令:
ansible-playbook -i hosts test.yaml -e "non_default_host=<somehost>"
结果弹出一堆警告,playbook 直接跳过执行:
[WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided host list is empty, only localhost is available [WARNING]: Could not match supplied host pattern, ignoring somehost PLAY [somehost] skipping: no hosts matched
情况2:将主机改为 all
把 test.yaml 里的 hosts 改成 all:
--- - hosts: all tasks: - debug: msg: 'This is the host specified'
再执行这条命令就能正常运行:
ansible-playbook -i 'somehost,' test.yaml
内容的提问来源于stack exchange,提问作者user_dev
相关产品推荐
相关产品推荐

