commit 1fb9ece91949fec2ea3eda8f88245b512274e049 Author: lhahn Date: Sun Sep 17 10:56:29 2023 +0200 Git initial commit diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..7ebbd16 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# cloud-wordpress + +Ansible role to provide a clean wordpress instance or multiple instances. \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100755 index 0000000..1207803 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,24 @@ +--- +cloud_apps: /opt +cloud_storage: /opt/storage +cloud_stage: prod +cloud_update: false +download_folder: "{{ cloud_apps }}/download-tmp" +shared_group: "cloud" + + +www_root: /var/www +www_group: www-data + +web_sites: + - domain: my-domain.tld + state: present + owner: user + root: "{{ www_root }}/my-domain.tld" + version: latest + worpress: true + db: + type: mariadb + name: db_name + user: db_user + pass: db_pass diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100755 index 0000000..ed97d53 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/meta/main.yml b/meta/main.yml new file mode 100755 index 0000000..8f7a4cb --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,19 @@ +--- +galaxy_info: + role_name: wordpress + namespace: hahn-cloud + author: Lars Hahn + company: OpenDevChain + license: MIT + description: Role to setup wordpress; shoudld be used in combination with an DB-, HTTP-Server and letsencrypt. + min_ansible_version: 2.7 + platforms: + - name: Debian + versions: + - 10 + galaxy_tags: + - wordpress +dependencies: + - mariadb + - php + - nginx \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100755 index 0000000..788f85a --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,25 @@ +--- +- name: setup download folder + file: + state: directory + path: "{{ download_folder }}" + +- name: setup wordpress folder + file: + state: directory + path: "{{ cloud_apps }}/wordpress" + mode: 0770 + owner: "{{ www_group }}" + group: "{{ shared_group }}" + +- name: download latest wordpress version + get_url: + url: https://wordpress.org/latest.tar.gz + dest: "{{ wordpress_latest_target }}" + +- name: setup WordPress websites + include_tasks: setup-wp.yml + loop: "{{ web_sites | json_query('[?wordpress==`true`&&state==`present`]') }}" + loop_control: + loop_var: wp + label: "{{ wp.domain }}" diff --git a/tasks/setup-wp.yml b/tasks/setup-wp.yml new file mode 100755 index 0000000..5dd3cd8 --- /dev/null +++ b/tasks/setup-wp.yml @@ -0,0 +1,70 @@ +--- +- name: set WP related config options + set_fact: + local_wp_root: "{{ wp.root | default(www_root + '/' + wp.domain) }}" + local_wp_owner: "{{ wp.owner | default('root') }}" + local_wp_version: "{{ wp.version | default('latest') }}" + +- name: "extract wordpress version {{ local_wp_version }} " + unarchive: + src: "{{ 'https://wordpress.org/wordpress-' + local_wp_version + '.tar.gz' if local_wp_version != 'latest' else wordpress_latest_target }}" + dest: "/tmp" + +- name: "extract wordpress archive to {{ local_wp_root }}" + copy: + remote_src: yes + src: "/tmp/wordpress/" + dest: "{{ local_wp_root }}" + force: no + mode: 770 + group: "{{ local_wp_owner }}" + owner: "{{ www_group }}" + + +- name: "adjust permissions for {{ local_wp_owner }}" + file: + path: "{{ local_wp_root }}" + group: "{{ local_wp_owner }}" + owner: "{{ www_group }}" + state: directory + recurse: yes + + +- name: generate example config + copy: + remote_src: yes + src: "{{ local_wp_root }}/wp-config-sample.php" + dest: "{{ local_wp_root }}/wp-config.php" + force: no + group: "{{ local_wp_owner }}" + owner: "{{ www_group }}" + +- name: adjust WP-config + lineinfile: + path: "{{ local_wp_root }}/wp-config.php" + regexp: "^define\\( '{{ item.conf }}'" + line: "define( '{{ item.conf }}', '{{ item.data }}' );" + loop: + - conf: "DB_NAME" + data: "{{ wp.db.name }}" + - conf: "DB_USER" + data: "{{ wp.db.user }}" + - conf: "DB_PASSWORD" + data: "{{ wp.db.pass }}" + loop_control: + label: "{{ item.conf }}" + +- name: adjust permissions in WP root for directories + changed_when: false + command: 'find {{ local_wp_root }} -type d -exec chmod 770 {} \;' + +- name: adjust permissions in WP root for files + changed_when: false + command: 'find {{ local_wp_root }} -type f -exec chmod 660 {} \;' + +- name: link wordpress folder to non-root user + file: + src: "{{ local_wp_root }}" + dest: "/home/{{ local_wp_owner }}/{{ wp.domain }}" + state: link + when: local_wp_owner != 'root' diff --git a/vars/main.yml b/vars/main.yml new file mode 100755 index 0000000..815724d --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +wordpress_latest_target: "{{ download_folder }}/wordpress-latest.tar.gz" \ No newline at end of file