我也为tomcat在Ubuntu和Linux上的部署编写了单独的剧本,而没有提到**。
when: ansible_distribution == 'Ubuntu'
**在剧本的每一行中,我只想在满足这个条件时才运行整个剧本。
这是我的密码
- hosts: all
tasks:
- name: including the playbook for ubuntu deployment
include: tomcat_ubuntu_new.yaml
when: ansible_distribution == 'Ubuntu'
- name: including the playbook for ubuntu deployment
include: tomcat_standalone.yaml
when: ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat'错误:
ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>
The error appears to be in '/etc/ansible/tomcat_ubuntu_new.yaml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- hosts: all
^ here我只想在基于ansible_distribution的主机上运行游戏手册。
我试过很多种方法,但没有人能给出明确的答案和解释。
发布于 2020-02-09 20:30:37
问:“我只想在基于ansible_distribution的主机上运行游戏手册。”
A:不可能包括一本剧本。这将递归地运行游戏手册。
只有输入一个剧本是可用的。此外,剧本不是一项任务。这是一个简单的工具,模块化的大型剧本与多个剧本。
Ansible 条件词不适用于import_playbook,就像它们不适用于剧本一样。
相反,可以创建一个将在剧本中使用的组。
$cat tomcat_ubuntu_new.yaml
---
- hosts: my_dynamic_group
tasks:
...例如,让我们创建组并导入剧本
---
- hosts: all
tasks:
- add_host:
name: "{{ item }}"
groups: my_dynamic_group
loop: "{{ groups.all }}"
when: hostvars[item].ansible_distribution == 'Ubuntu'
run_once: true
- import_playbook: tomcat_ubuntu_new.yamlhttps://stackoverflow.com/questions/60140478
复制相似问题