can roles and tasks exist in the same playbook?

后端 未结 4 1988
囚心锁ツ
囚心锁ツ 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:13

    You can also do pre_tasks: and post_tasks: if you need to do things before or after. From the Docs https://docs.ansible.com/playbooks_roles.html

    - hosts: localhost
    
      pre_tasks:
        - shell: echo 'hello in pre'
    
      roles:
        - { role: some_role }
    
      tasks:
        - shell: echo 'in tasks'
    
      post_tasks:
        - shell: echo 'goodbye in post'
    

    >

    Gives the output: PLAY [localhost]


    GATHERING FACTS *************************************************************** ok: [localhost]

    TASK: [shell echo 'hello in pre'] ********************************************* changed: [localhost]

    TASK: [some_role | shell echo 'hello from the role'] ************************** changed: [localhost]

    TASK: [shell echo 'in tasks'] ************************************************* changed: [localhost]

    TASK: [shell echo 'goodbye in post'] ****************************************** changed: [localhost]

    PLAY RECAP ******************************************************************** localhost : ok=5 changed=4 unreachable=0
    failed=0

    This is with ansible 1.9.1

提交回复
热议问题