ansible-playbook include.yml

ansible-playbook include.yml

我基本上想从远程主机获取动态信息,无论是 redhat 还是 debian,并相应地执行特定文件,该文件将根据操作系统风格安装 http 包。

[root@ansi1 ansible]# cat include.yml
---
 - hosts: all
   tasks:
   - name: Getting os info
     include_vars: "{{ ansible_os_family }}.yml"

   - include: setup-RedHat.yml
     when: ansible_os_family == 'RedHat'
[root@ansi1 ansible]#
[root@ansi1 ansible]#
[root@ansi1 ansible]#
[root@ansi1 ansible]# cat setup-RedHat.yml
---
 - hosts: all
   tasks:
   - name: htttp install
     yum: name=httpd state=present

ansible-playbook include.yml

错误:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/etc/ansible/setup-RedHat.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
 - hosts: all
   ^ here


The error appears to have been in '/etc/ansible/setup-RedHat.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
 - hosts: all
   ^ here

答案1

include当您在某个部分中使用该模块时tasks,不能包含剧本,只能包含任务列表。这意味着您的文件setup-RedHat.yml应该只包含以下内容:

- name: htttp install
  yum: name=httpd state=present

- name: more tasks...

答案2

include_vars指令旨在从作为值给出的文件中获取当前 playbook 的 Ansible 变量。在这种情况下,变量(可能在 和 中声明)从文件继承"{{ ansible_os_family }}.yml"

ansible_os_family事实上,Ansible 会自动从远程系统收集信息,它会解析为上下文中发行版的父发行版(如果有),如果没有父发行版,则解析为自身。因此,例如,如果您在 Debian 衍生产品上运行此程序,则要查找的文件名将变为Debian.yml

相关内容