/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Administration/Server/Provisioning/ansible/roles.txt

  • Committer: Suren A. Chilingaryan
  • Date: 2017-04-03 02:45:17 UTC
  • Revision ID: csa@suren.me-20170403024517-dwzj0z0k1cmhxm7u
Restructuring, OpenShift, Ansible, Git

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Roles
 
2
=====
 
3
 We also can include files with tasks: conditionally or unconditionally or even in the loop (variables are propogated)
 
4
  - name: task group
 
5
    include: <name>.yml
 
6
    [when|with_*|...]
 
7
    
 
8
 Or we can define a complete role, which may define the tasks, handlers, variables, etc. The roles are included from top
 
9
 level only like:
 
10
  - hosts: nodes
 
11
    roles:
 
12
        - role1
 
13
        - role2 param1=5000                                     - parametrizing
 
14
        - role2 param1=5001
 
15
 
 
16
 Including role from other roles.
 
17
    - include_role: 
 
18
        name: subrole
 
19
        *_from: filename.yml                                    - overrides the file to load vars/tasks/defaults from. I.e. instead main.yml the specified YaML description will be used
 
20
    vars:
 
21
        param1: value1
 
22
 
 
23
 It is also possible to icnlude a file with variables as a new variable with the specified name:
 
24
  - include_vars: file=vars.yml name=var_name                   - if name is ommited, the top level vars are loaded
 
25
    dir=<path> [extensions=list] [depth=l] [files_matching=re]  - if dir is specified, all files matching 're' in the directory and its subdirectoris until level 'l' are loaded. 
 
26
                                                                BEWARE: main.yml for some reason may be not included!
 
27
 
 
28
Directory Layout 
 
29
================
 
30
 meta/                                                          - information about the role
 
31
    main.yml
 
32
 defaults/                                                      - define default (least priority) facts for the role
 
33
    main.yml                                                    - variables from here are not propogated to next roles by default, but should be passed using 'set_fact'
 
34
 vars/                                                          
 
35
    main.yml                                                    - includede by default
 
36
    vars1.yml                                                   - variables included with 'vars_files'
 
37
 templates/                                                     - various templates used in tasks
 
38
    something.conf.j2
 
39
 files/                                                         - various files used in tasks and possibly distributed to the configured nodes
 
40
    ...
 
41
 tasks/                                                         - task lists
 
42
    main.yml                                                    - this task list is executed when roles in included, and may include more files from this folder
 
43
    action1.yml                                                 - this is not executed by default, but can be included from main.yml
 
44
 handlers/                                                      - define hanlders for the role
 
45
    main.yml
 
46
 library/                                                       - custom modules
 
47
 *_plugins/                                                     - various python plugins
 
48
 
 
49
 
 
50
Meta
 
51
====
 
52
dependencies:                                                   - ensures that listed roles are executed before this one 
 
53
 - { role: common, param1: val1, ... }
 
54
allow_duplicates: yes                                           - enforces all dependencies to be run before the role (even if they have been already executed in this playbook)