can roles and tasks exist in the same playbook?

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

    Actually this should be possible and I remember I did this a few times during testing. Might be something with your version - or the order does matter, so that the tasks will be executed after the roles.

    I would have posted this as a comment, rather than an answer, but I wouldn't be able to give the following example in a comment:

    Whatever might be the reason why your task is not executed, you can always separate your playbook into several plays, like so:

    ---
    # file: main.yml
    
    - hosts: fotk
      remote_user: fakesudo
      tasks:
      - name: create a developer user
        user: name={{ user }}
              password={{ password }}
              shell=/bin/bash
              generate_ssh_key=yes
              state=present
    
    - hosts: fotk
      remote_user: fakesudo
      roles:
      - { role: create_developer_environment, sudo_user: "{{ user }}" }
      - { role: vim, sudo_user: "{{ user }}" }
    

提交回复
热议问题