Home automating this site a bit
Post
Cancel

automating this site a bit

Automated jekyll deployment

So you most likely nobody saw the page that I tested the automated deployment. To do this I have created a not so clean playbook. I wanted to automate it a bit further since untill now it was a stupid manuall process.

So what steps did I needed to do before?

Before I did the following steps:

  • Create the post
  • ssh into to the server
  • pull the updated git repo
  • do some commands to build it
  • And wait a while

So What happens now?

Now the following happens:

  • Create the post
  • Open AWX
  • Press a button

I will do one more step later on so that I only need to create the post and that a gitlab runner just makes a api call to start the template in awx

The ansible playbook

The exciting stuff.. the ansible playbook I will say the formatting is all messed up of course

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
---
- hosts: jplace.nl
  become: false

  vars:
    bundle_install_need: false
    jekyll_build_needed: true

  tasks:
    - name: making sure directory exists
      ansible.builtin.file:
        path: /home/jeffrey/jplaceblog
        state: directory
        owner: jeffrey
        group: jeffrey
        mode: '0775'

    - name: getting latest version of jplace blog
      ansible.builtin.git:
        repo: [email protected]:jeffrey44113/jplaceblog.git
        dest: /home/jeffrey/jplaceblog
        single_branch: true
        version: main
        accept_hostkey: true
        update: true
        key_file: /home/jeffrey/.ssh/id_rsa

    - name: gemm requirements
      community.general.gem:
        name: ''
        state: latest
      loop:
        - jekyll
        - bundler

    - name: bundle config
      ansible.builtin.command:
        cmd: /home/jeffrey/gems/bin/bundle config set --local path 'vendor/bundle'
        chdir: /home/jeffrey/jplaceblog/
        executable: /bin/bash
      register: bundle_config
      when: bundle_install_need

    - name: running bundle install command
      ansible.builtin.command:
        cmd: /home/jeffrey/gems/bin/bundle install --path vendor/bundle
        chdir: /home/jeffrey/jplaceblog/
        executable: /bin/bash
      register: bundle_install
      when: bundle_install_need

    - name: building the pages
      ansible.builtin.command:
        cmd: /home/jeffrey/gems/bin/bundle exec jekyll build
        chdir: /home/jeffrey/jplaceblog/
        executable: /bin/bash
      register: jekyll_build
      when: jekyll_build_needed
      tags:
        - skip_this_tag
This post is licensed under CC BY 4.0 by the author.