summaryrefslogtreecommitdiff
path: root/roles/mkdocs/main.yml
blob: da0b8d0a210bebddee5173f30719cd6e06cc4e0f (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
- name: Container Setup

  vars:
    lxc_base: ansible-alpine3.11
    lxc_name: mkdocs

  import_playbook: ../common/tasks/lxc.yml

- name: Installing MkDocs
  hosts: mkdocs

  vars_files:
    - ../variables.yml

  tasks:

  - name: Ensuring group exists
    group:
      name: "{{ mkdocs_user }}"
      state: present

  - name: Creating user and making home directory
    user:
      system: yes
      state: present
      name: "{{ mkdocs_user }}"
      groups: "{{ mkdocs_user }}"
      home: "{{ mkdocs_home }}"

  - name: Installing the required dependencies
    apk:
      state: present
      update_cache: yes
      name:
        - sudo
        - git
        - supervisor

  - block:

    - name: Setting up python virtual environment
      shell: python3 -m venv .
      args:
        chdir: "{{ mkdocs_home }}"
        creates: bin/activate

    - name: Installing application
      shell: |
        . bin/activate
        pip install git+https://github.com/mkdocs/mkdocs@{{ mkdocs_version }}
        pip install -Iv mkdocs-material=={{ mkdocs_material_version }}
      args:
        chdir: "{{ mkdocs_home }}"
        creates: bin/mkdocs

    - name: Copying config file
      copy:
        src: mkdocs.yml
        dest: "{{ mkdocs_home }}"
        mode: '0644'
      register: mkdocsConfig

    - name: Creating document directory
      file:
        path: "{{ mkdocs_home }}/docs"
        state: directory

    - name: Copying index file
      copy:
        src: index.md
        dest: "{{ mkdocs_home }}/docs"
        mode: '0644'

    become: true
    become_user: "{{ mkdocs_user }}"

  - name: Copying supervisord config file
    copy:
      src: supervisord.conf
      dest: /etc/supervisord.conf
      mode: '0644'

  - name: Ensuring supervisord has been started and enabled
    service:
      name: supervisord
      state: restarted
      enabled: yes

  - name: Waiting for supervisor to become active
    wait_for:
      port: 9100

  - name: Ensuring application has been started
    supervisorctl:
      name: mkdocs
      state: restarted

  - name: Waiting for application to become active
    wait_for:
      port: 8000

  - name: Testing if webpage exists
    uri:
      url: http://0.0.0.0:8000
      return_content: yes