diff --git a/roles/blog/tasks/main.yml b/roles/blog/tasks/main.yml index 27da79f..9b9dcdc 100644 --- a/roles/blog/tasks/main.yml +++ b/roles/blog/tasks/main.yml @@ -4,18 +4,18 @@ repo: "https://github.com/CPunch/openpunk.git" dest: "/var/www/{{ domain }}" -# TODO: make idempotent (call the updateBlog script !!) -- name: Build blog - command: - cmd: hugo - chdir: "/var/www/{{ domain }}" - - name: Install updateBlog script template: src: templates/updateBlog dest: /usr/local/bin/updateBlog mode: u+rx +- name: Build blog + command: + cmd: updateBlog + register: blog_out + changed_when: blog_out.stdout != "up to date" + # Rebuild blog every hour - name: Setup blog cron job cron: diff --git a/roles/blog/templates/updateBlog b/roles/blog/templates/updateBlog index a571eb3..9573b4f 100644 --- a/roles/blog/templates/updateBlog +++ b/roles/blog/templates/updateBlog @@ -15,16 +15,14 @@ LOCAL=$(git rev-parse @) REMOTE=$(git rev-parse "$UPSTREAM") BASE=$(git merge-base @ "$UPSTREAM") if [ $LOCAL = $REMOTE ]; then - echo "blog is up to date!" + echo "up to date" elif [ $LOCAL = $BASE ]; then # there are changes to reset too # && we need to update our blog echo "missing changes!!" git reset --hard origin/main buildBlog -fi - -if [ ! -d "$PUBLIC_DIR" ] || [ ! -d "$TOR_DIR" ]; then +elif [ ! -d "$PUBLIC_DIR" ] || [ ! -d "$TOR_DIR" ]; then echo "missing directories..." buildBlog fi \ No newline at end of file