角色和任务可以存在于同一个剧本中吗? [英] can roles and tasks exist in the same playbook?

查看:25
本文介绍了角色和任务可以存在于同一个剧本中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

---
# 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
  roles:
  - { role: create_developer_environment, sudo_user: "{{ user }}" }
  - { role: vim, sudo_user: "{{ user }}" }

由于某种原因,创建用户任务没有运行.我在谷歌上搜索了我能想到的每一个关键短语,但没有成功.

For some reason the create user task is not running. I have searched every key phrase I can think of on Google to find an answer without success.

角色正在运行,这很奇怪.

The roles are running which is odd.

剧本是否可以同时包含任务和角色?

Is it possible for a playbook to contain both tasks and roles?

推荐答案

实际上这应该是可能的,我记得我在测试期间做过几次.可能与您的版本有关 - 或者顺序很重要,因此任务将在角色之后执行.

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 }}" }

这篇关于角色和任务可以存在于同一个剧本中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆