Razique Mahroua
2020-03-18 b85c91a8192593f6b62f93e11c971868964343a9
commit | author | age
6cbe31 1 = Galaxy and external roles
a5b75c 2
GC 3 To use galaxy roles in your config, just do the following:
4
f06bc3 5 . Create `requirements.yml` file in the config directory, for example:
a5b75c 6 +
f06bc3 7 .`ansible/configs/{{env_type}}/requirements.yml`
a5b75c 8 [source,yaml]
GC 9 ----
10 ---
11 - src: geerlingguy.docker
12   name: docker
f06bc3 13   version: '2.5.1'
a5b75c 14 ----
GC 15 . Use the role in the playbooks
16 +
f06bc3 17 .`ansible/configs/{{env_type}}/pre_software.yml`
a5b75c 18 [source,yaml]
GC 19 ----
20 - name: Some play
21   hosts:
22     - myhosts
23   become: true
24   gather_facts: False
25   tasks:
26     - name: install docker
27       include_role:
f06bc3 28         name: docker
a5b75c 29 ----
7d885e 30
998321 31 [NOTE]
GC 32 ====
33 Note that in the previous example, we use `include_role` which is *dynamic*. If you try to use the role with `role` or `import_role` it will fail because the role is dynamically downloaded at runtime.
34 ====
7d885e 35
f06bc3 36 [IMPORTANT]
GC 37 ====
38 Please use a pinned `version` in the `requirements.yml` file so the success of the deployment of your config does not depend on the stability of upstream galaxy roles.
39
40 [source,yaml]
41 .Make sure you use version pinning in `requirements.yml`
42 ----
43 - src: geerlingguy.docker
44   name: docker
45   version: '2.5.1'
46 ----
47 ====
48
49
50 When you run Ansible Agnostic Deployer, it will automatically fetch and create the role in your config directory: `ansible/configs/{{env_type}}/roles/docker` for example.
51
6cbe31 52 == Non-Galaxy external roles
GC 53
54 Roles in `requirements.yml` don't have to be in Galaxy, you can use any git repo.
55
56 [source,yaml]
57 .Another example of `requirements.yml` with git repo
58 ----
59 ---
60 # External role to setup grader host virtualenv and FTL grading infra
61
62 - src: https://github.com/redhat-gpte-devopsautomation/ftl-injector
63   name: ftl-injector
64   version: v0.7
65 ----
66
f06bc3 67 == Development workflow
GC 68
69 During development, the roles will be deployed and get in your way git-wise. To avoid that, there is a rule in the top-level link:../.gitignore[`.gitignore`] to ignore those dynamic roles:
70
71 .gitignore
72 ----
73 ansible/configs/*/roles
74 ----
75 The convention is:
76
77 > the "static" roles, those versioned in this repository, must live in link:../ansible/roles[`ansible/roles`] and the "dynamic" roles in your config directory `ansible/configs/{{env_type}}/roles`.
78
79 NOTE: Dynamic roles are not pushed in git, only the `requirements.yml` file is versioned.
80
81
82 == Multiple requirement files
83
84 Sometimes, for the same config, we need several `requirements.yml`. For example, one for PROD, one for DEV, etc.
85
86 You can create as many files as you want. When calling the playbook just override the `requirements_path` variable:
87
88 [source, bash]
89 ----
90 ansible-playbook main.yml -e requirements_path=ansible/configs/{{env_type}}/requirements-prod.yml [...]
91 ----