Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible 剧本中的角色和任务_Ansible - Fatal编程技术网

Ansible 剧本中的角色和任务

Ansible 剧本中的角色和任务,ansible,Ansible,我的ansible playbook与下面的代码类似: --- - hosts: localhost connection: local tasks: - name: "Create custom fact directory file: path: "/etc/ansible/facts.d" state: "directory" - name: "Insert custom fact file" copy: src: custom_fact

我的ansible playbook与下面的代码类似:

---
- hosts: localhost
 connection: local

 tasks:
 - name: "Create custom fact directory
   file:
    path: "/etc/ansible/facts.d"
    state: "directory"

 - name: "Insert  custom fact file"
   copy:
    src:  custom_fact.fact
    dest: /etc/ansible/facts.d/custom_fact.fact
    mode: 0755

roles:
- role1
- role2
一旦我使用ansible playbook命令运行playbook 只有角色正在运行,但任务没有运行

如果我对剧本中的角色进行注释,任务就会运行


如何使任务在角色之前运行?

将任务放在“在角色之前运行的任务”部分中


您还可能发现post_任务非常有用,它在角色之后运行任务

纠正压痕

- hosts: localhost
  connection: local
  tasks:
    - name: "Create custom fact directory
      file:
        path: ...