diff --git a/.ansible-lint b/.ansible-lint index 378fcff..b04781e 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,5 +1,5 @@ --- warn_list: - role-name + - name[play] - name[casing] - - no-handler diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 296f7cc..6776c26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,9 @@ jobs: python-version: '3.x' - name: Install test dependencies - run: pip install ansible-lint[community,yamllint] + run: | + pip install ansible-lint + ansible-galaxy install -r requirements.yml - name: Lint code run: | @@ -42,8 +44,6 @@ jobs: fail-fast: false matrix: include: - - distro: ubuntu1604 - ansible-version: '>=2.9, <2.10' - distro: ubuntu1604 ansible-version: '>=2.10, <2.11' - distro: ubuntu1604 @@ -62,7 +62,7 @@ jobs: python-version: '3.x' - name: Install test dependencies - run: pip install 'ansible${{ matrix.ansible-version }}' molecule[docker] docker + run: pip install 'ansible${{ matrix.ansible-version }}' molecule-plugins[docker] docker - name: Run Molecule tests run: | diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 73043c4..8596f09 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -4,6 +4,6 @@ become: true pre_tasks: - name: include vars - include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" roles: - ../../../ diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 6a4768b..4c28c8e 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -4,10 +4,11 @@ become: true tasks: - name: include vars - include_vars: "{{ playbook_dir }}/../../defaults/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/../../defaults/main.yml" - name: include vars - include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" - name: include tasks - include: "{{ playbook_dir }}/../../tests/tasks/pre.yml" + ansible.builtin.import_tasks: "{{ playbook_dir }}/../../tests/tasks/pre.yml" handlers: - - import_tasks: "{{ playbook_dir }}/../../tests/handlers/main.yml" + - name: include handlers + ansible.builtin.import_tasks: "{{ playbook_dir }}/../../tests/handlers/main.yml" diff --git a/requirements.yml b/requirements.yml index 3d5f1cd..05072c4 100644 --- a/requirements.yml +++ b/requirements.yml @@ -1,3 +1,4 @@ # requirements file --- -collections: [] +collections: + - name: community.mysql diff --git a/tasks/chown.yml b/tasks/chown.yml index ec73ee6..ff35547 100644 --- a/tasks/chown.yml +++ b/tasks/chown.yml @@ -1,7 +1,7 @@ # tasks file --- - name: change owner (and group) - file: + ansible.builtin.file: path: "{{ item.path }}" owner: "{{ item.owner | default('www-data') }}" group: "{{ item.group | default(item.owner) | default('www-data') }}" diff --git a/tasks/configure.yml b/tasks/configure.yml index e023288..1b0dff2 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,7 +1,7 @@ # tasks file --- - name: configure | create (data) directories - file: + ansible.builtin.file: path: "{{ item }}" state: directory owner: root diff --git a/tasks/core.yml b/tasks/core.yml index b472eb0..b4388b7 100644 --- a/tasks/core.yml +++ b/tasks/core.yml @@ -1,7 +1,7 @@ # tasks file --- - name: core | check download - command: > + ansible.builtin.command: > test -f {{ item.path }}/wp-load.php register: _check_download failed_when: false @@ -11,17 +11,18 @@ - wordpress-core-is-downloaded - name: core | download - command: > + ansible.builtin.command: > wp-cli core download --allow-root --no-color --path='{{ item.item.path }}' --locale='{{ item.item.locale | default('en_US') }}' + changed_when: true with_items: "{{ _check_download.results | default([]) }}" when: item.rc != 0 tags: - wordpress-core-downloaded - name: core | configure - command: > + ansible.builtin.command: > wp-cli core config --allow-root --no-color --path='{{ item.path }}' --dbname='{{ item.dbname }}' @@ -36,7 +37,7 @@ - wordpress-core-configure - name: core | identify installation - command: > + ansible.builtin.command: > wp-cli core is-installed --allow-root --no-color --path='{{ item.path }}' register: _check_installation @@ -47,20 +48,21 @@ - wordpress-core-is-installed - name: core | install - command: > + ansible.builtin.command: > wp-cli core install --allow-root --no-color --path='{{ item.item.path }}' --url='{{ item.item.url }}' --title='{{ item.item.title }}' --admin_name='{{ item.item.admin_name | default('admin') }}' --admin_email='{{ item.item.admin_email }}' --admin_password='{{ item.item.admin_password }}' + changed_when: true with_items: "{{ _check_installation.results | default([]) }}" when: item.rc != 0 tags: - wordpress-core-install - name: core | check install - command: > + ansible.builtin.command: > wp-cli core is-installed --allow-root --no-color --path='{{ item.path }}' changed_when: false diff --git a/tasks/main.yml b/tasks/main.yml index b10cf86..5336ff7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,60 +1,70 @@ # tasks file --- -- include: wp-cli.yml +- name: wp-cli + ansible.builtin.import_tasks: wp-cli.yml tags: - configuration - wordpress - wordpress-wp-cli -- include: core.yml +- name: core + ansible.builtin.import_tasks: core.yml tags: - configuration - wordpress - wordpress-core -- include: configure.yml +- name: configure + ansible.builtin.import_tasks: configure.yml tags: - configuration - wordpress - wordpress-configure -- include: wp-cron.yml +- name: wp-cron + ansible.builtin.import_tasks: wp-cron.yml tags: - configuration - wordpress - wordpress-wp-cron -- include: themes.yml +- name: themes + ansible.builtin.import_tasks: themes.yml tags: - configuration - wordpress - wordpress-themes -- include: plugins.yml +- name: plugins + ansible.builtin.import_tasks: plugins.yml tags: - configuration - wordpress - wordpress-plugins -- include: users.yml +- name: users + ansible.builtin.import_tasks: users.yml tags: - configuration - wordpress - wordpress-users -- include: options.yml +- name: options + ansible.builtin.import_tasks: options.yml tags: - configuration - wordpress - wordpress-options -- include: queries.yml +- name: queries + ansible.builtin.import_tasks: queries.yml tags: - configuration - wordpress - wordpress-queries -- include: chown.yml +- name: chown + ansible.builtin.import_tasks: chown.yml tags: - configuration - wordpress diff --git a/tasks/options.yml b/tasks/options.yml index 8d41f3b..8cb8ac7 100644 --- a/tasks/options.yml +++ b/tasks/options.yml @@ -1,7 +1,7 @@ # tasks file --- - name: add options - command: > + ansible.builtin.command: > wp-cli option --allow-root --no-color --path='{{ item.0.path }}' {{ item.1.command }} '{{ item.1.name }}' '{{ item.1.value }}' --autoload={{ 'yes' if item.1.autoload | default(true) else 'no' }} @@ -16,7 +16,7 @@ - wordpress-options-add - name: update options - command: > + ansible.builtin.command: > wp-cli option --allow-root --no-color --path='{{ item.0.path }}' {{ item.1.command }} '{{ item.1.name }}' '{{ item.1.value }}' @@ -30,7 +30,7 @@ - wordpress-options-update - name: delete options - command: > + ansible.builtin.command: > wp-cli option --allow-root --no-color --path='{{ item.0.path }}' {{ item.1.command }} '{{ item.1.name }}' diff --git a/tasks/plugins.yml b/tasks/plugins.yml index 4dfe2b8..cbb7835 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -1,7 +1,7 @@ # tasks file --- - name: plugins | identify installation - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin is-installed {{ item.1.name }} register: _check_installation_plugins failed_when: false @@ -14,9 +14,10 @@ - wordpress-plugins-is-installed-plugin - name: plugins | install | wordpress.org - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' {{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ item.item.1.name }} + changed_when: true with_items: "{{ _check_installation_plugins.results | default([]) }}" when: - item.item.1.name @@ -28,7 +29,7 @@ - wordpress-plugins-install-plugin-wordpress_org - name: plugins | install | zip | copy - copy: + ansible.builtin.copy: src: "{{ item.item.1.zip }}" dest: "{{ wordpress_data_path }}/plugins/{{ item.item.1.name }}.zip" owner: root @@ -46,9 +47,10 @@ - wordpress-plugins-install-plugin-zip-copy - name: plugins | install | zip | install - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' {{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ wordpress_data_path }}/plugins/{{ item.item.1.name }}.zip + changed_when: true with_items: "{{ _check_installation_plugins.results | default([]) }}" when: - item.item.1.name @@ -61,9 +63,10 @@ - wordpress-plugins-install-plugin-zip-install - name: plugins | install | url - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' {{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ item.item.1.url }} + changed_when: true with_items: "{{ _check_installation_plugins.results | default([]) }}" when: - item.item.1.name @@ -75,7 +78,7 @@ - wordpress-plugins-install-plugin-url - name: plugins | check install - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin is-installed {{ item.1.name }} changed_when: false with_subelements: @@ -86,7 +89,7 @@ - wordpress-plugins-check-install-plugin - name: plugins | activate - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin activate {{ item.1.name }} register: _check_activate_plugin changed_when: "'Success: Plugin' in _check_activate_plugin.stdout and not 'already' in _check_activate_plugin.stdout" @@ -100,7 +103,7 @@ - wordpress-plugins-activate-plugin - name: plugins | deactivate - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin deactivate {{ item.1.name }} register: _check_deactivate_plugin changed_when: "'Success: Plugin' in _check_deactivate_plugin.stdout and not 'already' in _check_deactivate_plugin.stdout" diff --git a/tasks/queries.yml b/tasks/queries.yml index 78a045d..9f74775 100644 --- a/tasks/queries.yml +++ b/tasks/queries.yml @@ -1,7 +1,7 @@ # tasks file --- - name: queries | execute queries - command: > + ansible.builtin.command: > wp-cli db query --allow-root --no-color --path='{{ item.0.path }}' "{{ item.1 }}; SELECT ROW_COUNT();" diff --git a/tasks/themes.yml b/tasks/themes.yml index 73c309f..b500a5d 100644 --- a/tasks/themes.yml +++ b/tasks/themes.yml @@ -1,7 +1,7 @@ # tasks file --- - name: themes | identify installation - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.0.path }}' theme is-installed {{ item.1.name }} register: _check_installation_themes failed_when: false @@ -14,8 +14,9 @@ - wordpress-themes-is-installed-theme - name: themes | install - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' theme install {{ item.item.1.name }} + changed_when: true with_items: "{{ _check_installation_themes.results | default([]) }}" when: - item.item.1.name @@ -24,7 +25,7 @@ - wordpress-themes-install-theme - name: themes | check install - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.0.path }}' theme is-installed {{ item.1.name }} changed_when: false with_subelements: @@ -35,7 +36,7 @@ - wordpress-themes-install-theme-check - name: themes | activate - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --path='{{ item.0.path }}' theme activate {{ item.1.name }} register: _check_activate_theme changed_when: "'Success: Switched to' in _check_activate_theme.stdout" diff --git a/tasks/users.yml b/tasks/users.yml index 4e6ac78..38f41c5 100644 --- a/tasks/users.yml +++ b/tasks/users.yml @@ -1,7 +1,7 @@ # tasks file --- - name: users | copy file - copy: + ansible.builtin.copy: src: "{{ item.users.src }}" dest: "{{ wordpress_data_path }}/users/{{ item.dbname }}.csv" owner: root @@ -13,8 +13,8 @@ tags: - wordpress-users-copy-file -- name: users | install - command: > +- name: users | install # noqa no-handler + ansible.builtin.command: > wp-cli user import-csv --allow-root --no-color --path='{{ item.item.path }}' {{ wordpress_data_path }}/users/{{ item.item.dbname }}.csv diff --git a/tasks/wp-cli.yml b/tasks/wp-cli.yml index 56ef4c5..a2245be 100644 --- a/tasks/wp-cli.yml +++ b/tasks/wp-cli.yml @@ -1,7 +1,7 @@ # tasks file --- - name: wp-cli | install - get_url: + ansible.builtin.get_url: url: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar dest: "{{ wordpress_wp_cli_install_dir }}/wp-cli" force: true @@ -12,7 +12,7 @@ - wordpress-wp-cli-install - name: wp-cli | check - command: > + ansible.builtin.command: > wp-cli --allow-root --no-color --info register: _check_info failed_when: "'WP-CLI' not in _check_info.stdout" diff --git a/tasks/wp-cron.yml b/tasks/wp-cron.yml index 3b0ca1a..188f3ce 100644 --- a/tasks/wp-cron.yml +++ b/tasks/wp-cron.yml @@ -1,7 +1,7 @@ # tasks file --- - name: wp-cron | disable wp-cron - lineinfile: + ansible.builtin.lineinfile: dest: "{{ item.path }}/wp-config.php" line: "{{ wordpress_disable_wp_cron_line }}" insertafter: '^\<\?php' @@ -14,7 +14,7 @@ - wordpress-wp-cron-disable-wp-cron - name: wp-cron | enable wp-cron - lineinfile: + ansible.builtin.lineinfile: dest: "{{ item.path }}/wp-config.php" line: "{{ wordpress_disable_wp_cron_line }}" state: absent @@ -24,7 +24,7 @@ - wordpress-wp-cron-enable-wp-cron - name: wp-cron | enable crond - cron: + ansible.builtin.cron: name: "{{ item.name }}" state: "{{ 'present' if item.cron is defined and item.cron.use_crond | default(false) else 'absent' }}" job: "wget -O /dev/null {{ item.url }}/wp-cron.php > /dev/null 2>&1" diff --git a/tests/handlers/main.yml b/tests/handlers/main.yml index 5b97ea2..47e863d 100644 --- a/tests/handlers/main.yml +++ b/tests/handlers/main.yml @@ -1,16 +1,16 @@ # handlers file --- - name: restart apache2 - service: + ansible.builtin.service: name: apache2 state: restarted - name: reload apache2 - service: + ansible.builtin.service: name: apache2 state: reloaded - name: restart mysql - service: + ansible.builtin.service: name: mysql state: restarted diff --git a/tests/tasks/pre.yml b/tests/tasks/pre.yml index 14c7a60..a21d9e0 100644 --- a/tests/tasks/pre.yml +++ b/tests/tasks/pre.yml @@ -1,7 +1,7 @@ # pre test file --- - name: percona server | add repo | dependencies - apt: + ansible.builtin.apt: name: - software-properties-common - dirmngr @@ -9,17 +9,17 @@ cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" - name: percona server | add repo - apt: + ansible.builtin.apt: deb: "https://repo.percona.com/apt/percona-release_latest.{{ ansible_distribution_release }}_all.deb" - name: php | add repo - apt_repository: + ansible.builtin.apt_repository: repo: 'ppa:ondrej/php' update_cache: true mode: 0644 - name: percona server | preseed - debconf: + ansible.builtin.debconf: name: "{{ item.name }}" question: "{{ item.question }}" value: "{{ item.value }}" @@ -36,7 +36,7 @@ changed_when: false - name: percona server | install - apt: + ansible.builtin.apt: name: - percona-server-client-5.7 - percona-server-server-5.7 @@ -45,7 +45,7 @@ state: "{{ apt_install_state | default('latest') }}" - name: php | install - apt: + ansible.builtin.apt: name: - apache2 - libapache2-mod-php7.4 @@ -62,12 +62,12 @@ state: "{{ apt_install_state | default('latest') }}" - name: percona server | start - service: + ansible.builtin.service: name: mysql state: started - name: percona server | configure - copy: + ansible.builtin.copy: dest: '~root/.my.cnf' content: | [client] @@ -80,18 +80,18 @@ mode: 0600 - name: percona server | ensure database - mysql_db: + community.mysql.mysql_db: name: wordpress encoding: utf8mb4 collation: utf8mb4_unicode_ci - name: percona server | ensure grants - mysql_user: + community.mysql.mysql_user: name: wordpress password: 'heCrE7*d2KEs' priv: 'wordpress.*:ALL' - name: apache server | start - service: + ansible.builtin.service: name: apache2 state: started diff --git a/tests/test.yml b/tests/test.yml index 18ce34e..f289193 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -5,10 +5,11 @@ become: true pre_tasks: - name: include vars - include_vars: "{{ playbook_dir }}/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml" - name: include tasks - include: "{{ playbook_dir }}/tasks/pre.yml" + ansible.builtin.import_tasks: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ handlers: - - import_tasks: "{{ playbook_dir }}/handlers/main.yml" + - name: include handlers + ansible.builtin.import_tasks: "{{ playbook_dir }}/handlers/main.yml" diff --git a/tests/vagrant.yml b/tests/vagrant.yml index 16360cf..8949a4e 100644 --- a/tests/vagrant.yml +++ b/tests/vagrant.yml @@ -5,13 +5,14 @@ become: true pre_tasks: - name: include vars - include_vars: "{{ playbook_dir }}/vars/main.yml" + ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml" - name: include tasks - include: "{{ playbook_dir }}/tasks/pre.yml" + ansible.builtin.import_tasks: "{{ playbook_dir }}/tasks/pre.yml" roles: - ../../ handlers: - - import_tasks: "{{ playbook_dir }}/handlers/main.yml" + - name: include handlers + ansible.builtin.import_tasks: "{{ playbook_dir }}/handlers/main.yml" vars: wordpress_installs: - name: wordpress