can roles and tasks exist in the same playbook?

后端 未结 4 1979
囚心锁ツ
囚心锁ツ 2021-02-12 12:48
---
# file: main.yml

- hosts: fotk
  remote_user: fakesudo
  tasks:
  - name: create a developer user
    user: name={{ user }}
          password={{ password }}
               


        
4条回答
  •  遇见更好的自我
    2021-02-12 13:04

    Short follow up to the already mentioned options by quoting the latest Ansible docs docs.ansible.com/latest/playbooks_reuse_roles:

    As of Ansible 2.4, you can now use roles inline with any other tasks using import_role or include_role:

    ---    
    - hosts: webservers
      tasks:
        - debug:
          msg: "before we run our role"
        - import_role:
          name: example
        - include_role:
          name: example
        - debug:
          msg: "after we ran our role"`
    

    Code snippet is also from Ansible docs.

    Be aware of the difference between static (import*) & dynamic (include*) usage.

提交回复
热议问题