summaryrefslogtreecommitdiff
path: root/vmdb/plugins/ansible.mdwn
blob: b0293a5fcdce9c0577d07d2f792eff7852a68570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Step: ansible
-----------------------------------------------------------------------------

Run Ansible using a provided playbook, to configure the image. vmdb2
sets up Ansible so that it treats the image as the host being
configured (via the `chroot` connection). The image MUST have Python
installed (version 2 or 3 depending on Ansible version).

Step keys:

* `ansible` — REQUIRED; value is the tag of the root filesystem.

* `config_file` — OPTIONAL; value is the filename of an Ansible
  configuration file, relative to the .vmdb file.

* `group` — OPTIONAL; the name of the Ansible inventory group. Defaults
  to "image"

* `playbook` — REQUIRED; value is the filename of the Ansible
  playbook, relative to the .vmdb file.

* `tags` — OPTIONAL; a comma-separated list of Ansible tags to execute

* `extra_vars` — OPTIONAL; a dictionary defining variables to pass to the
  Ansible playbook.

Example (in the .vmdb file):

    - apt: install
      tag: root
      packages: [python]

    - ansible: root
      playbook: foo.yml
      tags: bar
      config_file: ansible.cfg
      group: AwesomeGroup
      extra_vars:
        iface:
          name: eth0

Example (`foo.yml`):

    - hosts: image
      tasks:

        - name: "set /etc/hostname"
          shell: |
            echo "{{ hostname }}" > /etc/hostname

        - name: "unset root password"
          shell: |
            sed -i '/^root:[^:]*:/s//root::/' /etc/passwd

        - name: "configure networking"
          copy:
            content: |
              auto {{ iface.name }}
              iface {{ iface.name }} inet dhcp
              iface {{ iface.name }} inet6 auto
            dest: /etc/network/interfaces.d/wired

      vars:
        hostname: discworld