安莎角色。有没有办法使目录结构更简洁?

时间:2017-01-06 17:19:50

标签: ansible ansible-playbook

现在我的目录结构如下:

roles
├── python2
│   └── tasks
│       └── main.yml
└── redis
    ├── handlers
    │   └── main.yml
    └── tasks
        └── main.yml

这有点过于复杂。有没有办法让它变得像?

roles
├── python2
│   └── tasks.yml
└── redis
    ├── tasks.yml
    └── handlers.yml

我查了一份文件,看起来没有这样的选择。

1 个答案:

答案 0 :(得分:2)

据我所知,没有办法用角色来做这件事,但听起来你根本不需要角色。你可以改用包含。 http://docs.ansible.com/ansible/playbooks_roles.html

您的文件结构可能如下所示:

main.yml
includes
├── python2
│   └── tasks.yml
└── redis
    ├── tasks.yml
    └── handlers.yml

main.yml
python2Tasks.yml
redisTasks.yml
redisHandlers.yml

main.yml
tasks
├── python2.yml
└── redis.yml
handlers
└── redis.yml

main.yml看起来像:

- name: python2 play
  hosts: python2Hosts
  tasks:
    - include: includes/python2/tasks.yml

- name: redis play
  hosts: redisHosts
  tasks:
    - include: includes/redis/tasks.yml
  handlers:
    - include: includes/redis/handlers.yml