Ansible Playbook 无法正确解析变量
Ansible Playbook not resolving variable correctly
我正在使用 ansible 并且 运行 剧本有问题
site.yml:
---
- name: Test Ansible Playbook
hosts: '{{ myhosts }}'
sudo: no
roles:
- myRole
以及 myRole 文件:
---
- name: Node script
hosts: '{{ myhosts }}'
sudo: no
tasks:
- name: Start Tomcat
service: name=tomcat state=started enabled=yes
当我尝试 运行 命令时:ansible-playbook "-e 'myhosts=myHostName'" site.yml
我收到以下错误:
ERROR: hosts is not a legal parameter in an Ansible task or handler
ERROR: hosts is not a legal parameter in an Ansible task or handler
这就是问题所在。在角色的任务文件中,您可以定义任务 - 仅此而已。这些任务将在哪些主机上执行在剧本中定义。
你的任务文件应该只包含这个:
---
- name: Start Tomcat
service: name=tomcat
state=started
enabled=yes
...
我正在使用 ansible 并且 运行 剧本有问题
site.yml:
---
- name: Test Ansible Playbook
hosts: '{{ myhosts }}'
sudo: no
roles:
- myRole
以及 myRole 文件:
---
- name: Node script
hosts: '{{ myhosts }}'
sudo: no
tasks:
- name: Start Tomcat
service: name=tomcat state=started enabled=yes
当我尝试 运行 命令时:ansible-playbook "-e 'myhosts=myHostName'" site.yml
我收到以下错误:
ERROR: hosts is not a legal parameter in an Ansible task or handler
ERROR: hosts is not a legal parameter in an Ansible task or handler
这就是问题所在。在角色的任务文件中,您可以定义任务 - 仅此而已。这些任务将在哪些主机上执行在剧本中定义。
你的任务文件应该只包含这个:
---
- name: Start Tomcat
service: name=tomcat
state=started
enabled=yes
...