diff --git a/README.md b/README.md index 0cb1036..aa65fd4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,79 @@ -# ansible-role-hugo-deploy +ansible-role-hugo-deploy +========= -This role is used to deploy a website managed by Hugo on a webserver. \ No newline at end of file +This role is used to deploy a website managed by Hugo on a webserver. + +Requirements +------------ + +None, any package needed is downloaded by the role itself. + +It's written for Debian tho. + +Role Variables +-------------- + +``` +hugo_deploy_site_url: "" +``` +The URL used to build the website with Hugo. Used for the `--baseURL` argument. + +``` +hugo_deploy_website_git_url: "" +``` + +The git repo's URL for the website. + +``` +hugo_deploy_download_path: "/opt/hugo_deploy" +``` + +Where, on the server, will the website will be downloaded before it's built. + +``` +hugo_deploy_dest_webroot: "/var/www/{{hugo_deploy_site_url}}" +``` + +Where to copy the website once it's built. + +``` +hugo_deploy_build_openring: no +``` + +This role can use [Openring](https://git.sr.ht/~sircmpwn/openring) to build a Openring. + +Dependencies +------------ + +None. + +Example Playbook +---------------- + + --- + - name: Converge + become: yes + hosts: all + vars_files: + - vars.yml + tasks: + - name: "Include ansible-role-hugo-deploy" + include_role: + name: "ansible-role-hugo-deploy" + + + --- + hugo_deploy_site_url: "https://example.com" + hugo_deploy_website_git_url: "http://git.example.xyz/user/blog.git" + hugo_deploy_download_path: "/opt/hugo_deploy" + hugo_deploy_build_openring: yes + +License +------- + +AGPLv3 + +Author Information +------------------ + +Built by [N07070]( https://n07070.xyz). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..9c2f96d --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,8 @@ +--- +# defaults file for ansible-role-hugo-deploy + +hugo_deploy_site_url: "" +hugo_deploy_website_git_url: "" +hugo_deploy_download_path: "/opt/hugo_deploy" +hugo_deploy_dest_webroot: "/var/www/{{hugo_deploy_site_url}}" +hugo_deploy_build_openring: no diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..1c6367e --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for ansible-role-hugo-deploy diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..41149dc --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,55 @@ +galaxy_info: + author: nono + description: This role is used to deploy a website managed by Hugo on a webserver. + role_name: ansible_role_hugo_deploy + namespace: nono + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: + - hugo + - static + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst new file mode 100644 index 0000000..0c4bf5c --- /dev/null +++ b/molecule/default/INSTALL.rst @@ -0,0 +1,23 @@ +********************************* +Vagrant driver installation guide +********************************* + +Requirements +============ + +* Vagrant +* Virtualbox, Parallels, VMware Fusion, VMware Workstation or VMware Desktop + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ pip install 'molecule_vagrant' diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..3edaa7f --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,10 @@ +--- +- name: Converge + become: yes + hosts: all + vars_files: + - vars.yml + tasks: + - name: "Include ansible-role-hugo-deploy" + include_role: + name: "ansible-role-hugo-deploy" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..e5e75db --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,16 @@ +--- +dependency: + name: galaxy +driver: + name: vagrant + provider: + name: virtualbox +platforms: + - name: instance + box: debian/bullseye64 + memory: 512 + cpus: 1 +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/default/vars.yml b/molecule/default/vars.yml new file mode 100644 index 0000000..e4a4be7 --- /dev/null +++ b/molecule/default/vars.yml @@ -0,0 +1,6 @@ +--- + +hugo_deploy_site_url: "localhost" +hugo_deploy_website_git_url: "" +hugo_deploy_download_path: "/opt/hugo_deploy" +hugo_deploy_build_openring: yes diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..79044cd --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,10 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: Example assertion + assert: + that: true diff --git a/tasks/build.yml b/tasks/build.yml new file mode 100644 index 0000000..00a90c4 --- /dev/null +++ b/tasks/build.yml @@ -0,0 +1,31 @@ + +- name: Verify the webroot exists + file: + path: "{{ hugo_deploy_dest_webroot }}" + state: directory + owner: www-data + group: www-data + mode: 0755 + +- block: + - name: Build Openring + shell: + cmd: go build + chdir: "{{ hugo_deploy_download_path}}/tools/openring" + + - name: Generate Openring + shell: + cmd: ./openring -s https://www.laquadrature.net/feed -s https://blog.mondediplo.net/rss/ -s https://solar.lowtechmagazine.com/feeds/all-en.rss.xml < {{hugo_deploy_download_path}}/themes/blogotheme/layouts/partials/openring-in.html > {{hugo_deploy_download_path}}/themes/blogotheme/layouts/partials/openring-out.html + chdir: "{{hugo_deploy_download_path}}/tools/openring/" + when: hugo_deploy_build_openring + +- name: Building the website with Hugo + shell: + cmd: hugo --themesDir themes --theme blogotheme --baseURL="http://{{ hugo_deploy_site_url }}" --enableGitInfo --minify --templateMetrics + chdir: "{{ hugo_deploy_download_path }}" + +- name: Copy the website to it's webroot + copy: + remote_src: yes + src: "{{ hugo_deploy_download_path }}/public/" + dest: "{{ hugo_deploy_dest_webroot }}" diff --git a/tasks/dependecies.yml b/tasks/dependecies.yml new file mode 100644 index 0000000..d01f245 --- /dev/null +++ b/tasks/dependecies.yml @@ -0,0 +1,22 @@ + +- name: Update the APT cache + apt: + update_cache: yes + +- name: Make sure Hugo is installed + package: + name: hugo + state: present + +- name: Make sure git is installed + package: + name: git + state: present + + +- block: + - name: Make sure Golang is installed + package: + name: golang + state: present + when: hugo_deploy_build_openring diff --git a/tasks/import-website.yml b/tasks/import-website.yml new file mode 100644 index 0000000..8e0f5db --- /dev/null +++ b/tasks/import-website.yml @@ -0,0 +1,13 @@ + +- name: Verify that the path to download the website exists + file: + path: "{{ hugo_deploy_download_path }}" + state: directory + mode: '0755' + +- name: Clone the git repo for the website + git: + repo: "{{ hugo_deploy_website_git_url }}" + dest: "{{ hugo_deploy_download_path }}" + accept_hostkey: yes + force: yes diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..d5428ca --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,11 @@ +--- +# tasks file for ansible-role-hugo-deploy + +- name: Verify dependecies + import_tasks: dependecies.yml + +- name: Import the website + import_tasks: import-website.yml + +- name: Build the website + import_tasks: build.yml diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..e0d4a95 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ansible-role-hugo-deploy diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..7e4e25f --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for ansible-role-hugo-deploy