967d1dbccda7b835f43d37784069e97186d0316f
[noc.git] / ansible / README.md
1 Overview
2 ========
3
4 This should provide a short overview on how to use ansible
5
6 ### basic ansible playbook call
7
8 ```
9 #   -C ... check
10 #   -D ... show diff of changes
11 ansible-playbook foo.yml -D -C
12 ```
13
14 ### basic ansible call
15 ```
16 #   -m ... load module shell
17 #   -a ... arguments to module call
18 ansible vex -m shell -a 'uname -a'
19 ansible servers -m apt -a 'name=foo state=present'
20 ansible desktops -m file -a 'name=/make/sure/this/file/is/gone state=absent'
21 ```
22
23 ### check if all server are reachable
24 ```
25 ansible servers -m ping
26 ```
27
28 ### deploy playbook
29 ```
30 ansible-playbook foo.yml
31 ```
32
33 ### deploy a single role to a single host
34 ```
35 ./apply-role.sh wuerfel base
36 ```
37
38 ### deploy a single role to a group of hosts with check-mode to see what would be done
39 ```
40 ./apply-role.sh servers base -C -D
41 ```
42
43 ansible-lint
44 ------------
45
46 We use ansible-lint to check all roles when changes are pushed to Github.
47 Some rules have been globally disabled. See [.ansible-lint](/ansible/.ansible-lint)
48 for a list of all disabled rules. If ansible-lint produces a false positive for
49 a specific task you can disable it by adding the following to the task:
50
51 ```
52   tags:
53   - skip_ansible_lint
54 ```
55
56 For now only roles are checked and every role must be manually added to the
57 generic playbook [_lint_roles.yml](/ansible/_lint_roles.yml) in order to be checked.
58 If an entire role should be skipped please add it to the playbook commented out
59 and supply a reason why this roles must be skipped.
60
61
62 Local ssh config
63 ----------------
64
65 By default hosts in the inventory use the FQDNs as the name so most
66 hosts should be reachable without any special configuration.
67 In addition r3 NOC uses the `localconfig` playbook/role to generate a
68 ssh config snippet to add nicer/shorter aliases for the hosts and also
69 to automatically add jump hosts and some other special settings.
70
71 The way this works is that config snippets are generated inside
72 `~/.ssh/config.d/` and (optionally) then compiled to a single file
73 `~/.ssh/config`. If you want to use it as well you should move your
74 current ssh config file to `~/.ssh/config.d/` and run the playbook
75 `localconfig.yml`.
76 In order to make the generated config snippet work for different
77 people the role sources the file `~/.ssh/r3_localconfig.yml`.
78 All variables inside that file will take precedence of files from
79 `host_vars`, `group_vars`, gathered facts, etc.
80
81
82 Secrets
83 -------
84
85 See [README_vault.md](/ansible/README_vault.md) on how to create vaults.
86
87 In general vaults should live in `host_vars/<hostname>/vault.yml` or
88 `group_vars/<groupname>/vault.yml`. The variables defined inside the
89 vaults should be prefixed with `vault_` and be referenced by other
90 variables and not used directly in plays and roles. For example if you
91 want to set a secret variable `root_pasword` for host `foo` there should
92 be two files:
93   * `host_vars/foo/main.yml`:
94     ```
95     root_password: "{{ vault_root_password }}"
96     ```
97   * `host_vars/foo/vault.yml`:
98     ```
99     vault_root_password: "this-is-very-secret"
100     ```
101
102 Of course the latter file needs to be created using `ansible-vault`.
103
104 If you want to store secrets that by default shouldn't be automatically
105 exposed to hosts and groups as variables please put the vault files into
106 `secrets` directory and name them <some-name>.vault.yml.
107
108 r3 NOC uses [ansible-vault-tools](https://github.com/building5/ansible-vault-tools)
109 to manage/diff/merge changes in vaults.