首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于ansible_distribution运行游戏手册

基于ansible_distribution运行游戏手册
EN

Stack Overflow用户
提问于 2020-02-09 19:27:19
回答 1查看 581关注 0票数 1

我也为tomcat在Ubuntu和Linux上的部署编写了单独的剧本,而没有提到**。

when: ansible_distribution == 'Ubuntu'

**在剧本的每一行中,我只想在满足这个条件时才运行整个剧本。

这是我的密码

代码语言:javascript
复制
 - 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'

错误:

代码语言:javascript
复制
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的主机上运行游戏手册。

我试过很多种方法,但没有人能给出明确的答案和解释。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-09 20:30:37

问:“我只想在基于ansible_distribution的主机上运行游戏手册。”

A:不可能包括一本剧本。这将递归地运行游戏手册。

只有输入一个剧本是可用的。此外,剧本不是一项任务。这是一个简单的工具,模块化的大型剧本与多个剧本。

Ansible 条件词不适用于import_playbook,就像它们不适用于剧本一样。

相反,可以创建一个将在剧本中使用的组。

代码语言:javascript
复制
$cat tomcat_ubuntu_new.yaml
---
- hosts: my_dynamic_group
  tasks:
  ...

例如,让我们创建组并导入剧本

代码语言:javascript
复制
---
- 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.yaml
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60140478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档