<commit_before>---
- hosts: all
  vars:
    path: "{{ vccw.document_root }}/{{ vccw.wp_siteurl }}"
    user: "{{ ansible_env.USER | default( 'ubuntu' ) }}"

  tasks:

  # Database Settings
  - name: Create Database
    mysql_db:
      login_user: root
      name: "{{ vccw.db_name }}"
      state: present

  - name: Create MySQL user
    mysql_user:
      login_user: root
      name: "{{ vccw.db_user }}"
      password: "{{ <PASSWORD> }}"
      priv: "{{ vccw.db_name }}.*:ALL"
      host: "%"
      state: present

  - name: "Change owner of the {{ path }}"
    become: yes
    file:
      path: "{{ path }}"
      state: directory
      owner: "{{ user }}"
      group: "{{ user }}"
      mode: 0755
      recurse: yes

  - name: "Remove index.html from document root"
    become: yes
    file:
      path: "{{ path }}/index.html"
      state: absent

####   # download wordpress
####   - name: Run `wp core download`
####     command: |
####       wp core download
####       --path={{ path }}
####       --version={{ vccw.version }}
####       --force

  # wp-config.php
####  - name: Create temporary file for extra-php in wp-config.php
####    template:
####      src: templates/extra-wp-config.php
####      dest: "/tmp/extra-wp-config.php"
####  - name: Run `wp core config`
####    shell: |
####       wp core config \
####       --force \
####       --path={{ path }} \
####       --dbhost={{ vccw.db_host }} \
####       --dbname={{ vccw.db_name }} \
####       --dbuser={{ vccw.db_user }} \
####       --dbpass={{ vccw.db_pass }} \
####       --dbprefix={{ vccw.db_prefix }} \
####       --locale={{ vccw.lang }} \
####       --extra-php < /tmp/extra-wp-config.php

  # Reset Database
  - name: Run `wp db reset`
    command: wp db reset --yes --path={{ path }}
    when: vccw.reset_db_on_provision

  # Import Database
  - name: Run `wp db import`
    command: wp db import {{ path }}data.sql --path={{ path }}
    when: vccw.reset_db_on_provision
    ignore_errors: yes

####   # install wordpress
####   - name: Run `wp core install`
####     command: |
####       wp core install
####       --path={{ path }}
####       --url=http://{{ vccw.hostname }}/{{ vccw.wp_siteurl }}
####       --title='{{ vccw.title }}'
####       --admin_user={{ vccw.admin_user }}
####       --admin_password={{ <PASSWORD> }}
####       --admin_email={{ vccw.admin_email }}
#### 
####   - name: Create index.php for wp_siteurl
####     when: vccw.wp_siteurl != ''
####     template:
####       src: templates/index.php
####       dest: /tmp/index.php
####   - name: Move index.php for wp_siteurl
####     when: vccw.wp_siteurl != ''
####     command: "mv /tmp/index.php {{ vccw.document_root }}/index.php"
#### 
####   - name: Create `.gitignore`
####     get_url:
####       url: https://raw.githubusercontent.com/github/gitignore/master/WordPress.gitignore
####       dest: /tmp/.gitignore
####       mode: 0644
####       force: yes
####   - name: Move `.gitignore`
####     command: "mv /tmp/.gitignore {{ path }}/.gitignore"

  - name: Run `wp core language install`
    command: |
      wp core language install {{ vccw.lang }}
      --path={{ path }}
      --skip-themes
      --activate

  # Install Plugins
  - name: Run `wp plugin install`
    command: |
      wp plugin install {{ item }}
      --activate
      --skip-themes
      --path={{ path }}
    with_items: "{{ vccw.plugins | default([]) }}"

  # Install wp-multibyte-patch
  - name: Run `wp plugin install wp-multibyte-patch`
    command: |
      wp plugin install wp-multibyte-patch
      --activate
      --skip-themes
      --path={{ path }}
    when: vccw.lang == 'ja'

  # Check exsist Theme
  - name: Run `wp theme is-installed`
    command: |
      wp theme is-installed {{ vccw.theme }}
      --skip-themes
      --path={{ path }}
    register: theme_is_installed
    ignore_errors: True
    when: vccw.theme != ''

  # Install Theme
  - name: Run `wp theme install`
    command: |
      wp theme install {{ vccw.theme }}
      --skip-themes
      --path={{ path }} --activate
    when: vccw.theme != '' and theme_is_installed.stdout == "1"

  - name: Run `wp theme activate`
    command: |
      wp theme activate {{ vccw.theme }}
      --skip-themes
      --path={{ path }}
    when: vccw.theme != ''

  # Import Theme Unit Test Data
  - name: Run `wp plugin install wordpress-importer`
    command: |
      wp plugin install wordpress-importer
      --skip-themes
      --activate
      --path={{ path }}
    when: vccw.theme_unit_test
  - name: Download WordPress theme unit test data
    when: vccw.theme_unit_test
    get_url:
      url: "{{ vccw.theme_unit_test_uri }}"
      dest: "/tmp/theme-unit-test-data.xml"
  - name: Import WordPress theme unit test data
    when: vccw.theme_unit_test
    command: |
      wp import
      /tmp/theme-unit-test-data.xml
      --authors=create
      --path={{ path }}
      --skip-themes

  # Import Options
  - name: Run `wp options update`
    command: |
      wp option update {{ item.key }} '{{ item.value }}'
      --path={{ path }}
      --skip-themes
    with_dict: "{{ vccw.options }}"

  # Localization
  - name: Get the timezone
    command: |
      wp eval "echo _x( '0', 'default GMT offset or timezone string' );"
      --path={{ path }}
      --skip-themes
    register: timezone
  - name: Update timezone
    command: |
      wp option update timezone_string '{{ timezone.stdout }}'
      --path={{ path }}
      --skip-themes

  - name: Get the date format
    command: |
      wp eval "echo __( 'M jS Y' );"
      --path={{ path }}
      --skip-themes
    register: date_format
  - name: Update date format
    command: |
      wp option update date_format '{{ date_format.stdout }}'
      --path={{ path }}
      --skip-themes

  # Setting Permalink
  - name: Run `wp rewrite structure`
    when: vccw.rewrite_structure != ''
    command: |
      wp rewrite structure {{ vccw.rewrite_structure }}
      --path={{ path }}
      --skip-themes
  - name: Flush rewrite rules
    when: vccw.rewrite_structure != ''
    command: |
      wp rewrite flush
      --hard
      --path={{ path }}
      --skip-themes

 # multisite Settings
  - name: Run `wp core multisite-convert`
    when: vccw.multisite
    command: |
      wp core multisite-convert
      --path={{ path }}
      --skip-themes
  - name: Create `.htaccess` for multisite
    when: vccw.multisite
    template:
      src: templates/multisite-htaccess
      dest: /tmp/.htaccess
  - name: Move `.htaccess` for multisite
    when: vccw.multisite
    command: "mv /tmp/.htaccess {{ vccw.document_root }}/.htaccess"
  - name: Setting up Wordpress multisite options
    command: |
      wp network meta update 1 {{ item.key }} '{{ item.value }}'
      --path={{ path }}
      --skip-themes
    with_dict: "{{ vccw.multisite_options | default({}) }}"
    when: vccw.multisite

  # Generate Movefile
  - name: Check `wp scaffold movefile` exists.
    shell: bash -lc 'wp help scaffold movefile &> /dev/null; echo $?'
    register: is_command
  - stat:
      path: "{{ vccw.vagrant_dir }}/Movefile"
    register: is_movefile
  - name: Create a Movefile
    become: no
    shell: /bin/bash -lc "wp scaffold movefile --force"
    args:
      chdir: "{{ vccw.vagrant_dir }}"
      creates: Movefile
    when: is_command.stdout == "0" and is_movefile.stat.exists != true
<commit_msg>fix(provisioning): use config script<commit_after>---
- hosts: all
  vars:
    path: "{{ vccw.document_root }}/{{ vccw.wp_siteurl }}"
    user: "{{ ansible_env.USER | default( 'ubuntu' ) }}"

  tasks:

  # Database Settings
  - name: Create Database
    mysql_db:
      login_user: root
      name: "{{ vccw.db_name }}"
      state: present

  - name: Create MySQL user
    mysql_user:
      login_user: root
      name: "{{ vccw.db_user }}"
      password: "{{ <PASSWORD> }}"
      priv: "{{ vccw.db_name }}.*:ALL"
      host: "%"
      state: present

  - name: "Change owner of the {{ path }}"
    become: yes
    file:
      path: "{{ path }}"
      state: directory
      owner: "{{ user }}"
      group: "{{ user }}"
      mode: 0755
      recurse: yes

  - name: "Remove index.html from document root"
    become: yes
    file:
      path: "{{ path }}/index.html"
      state: absent

####   # download wordpress
####   - name: Run `wp core download`
####     command: |
####       wp core download
####       --path={{ path }}
####       --version={{ vccw.version }}
####       --force

  # wp-config.php
  - name: Create temporary file for extra-php in wp-config.php
    template:
      src: templates/extra-wp-config.php
      dest: "/tmp/extra-wp-config.php"
  - name: Run `wp core config`
    shell: |
       wp core config \
       --force \
       --skip-salts \
       --path={{ path }} \
       --dbhost={{ vccw.db_host }} \
       --dbname={{ vccw.db_name }} \
       --dbuser={{ vccw.db_user }} \
       --dbpass={{ vccw.db_pass }} \
       --dbprefix={{ vccw.db_prefix }} \
       --locale={{ vccw.lang }} \
       --extra-php < /tmp/extra-wp-config.php

  # Reset Database
  - name: Run `wp db reset`
    command: wp db reset --yes --path={{ path }}
    when: vccw.reset_db_on_provision

  # Import Database
  - name: Run `wp db import`
    command: wp db import {{ path }}data.sql --path={{ path }}
    when: vccw.reset_db_on_provision
    ignore_errors: yes

####   # install wordpress
####   - name: Run `wp core install`
####     command: |
####       wp core install
####       --path={{ path }}
####       --url=http://{{ vccw.hostname }}/{{ vccw.wp_siteurl }}
####       --title='{{ vccw.title }}'
####       --admin_user={{ vccw.admin_user }}
####       --admin_password={{ <PASSWORD> }}
####       --admin_email={{ vccw.admin_email }}
#### 
####   - name: Create index.php for wp_siteurl
####     when: vccw.wp_siteurl != ''
####     template:
####       src: templates/index.php
####       dest: /tmp/index.php
####   - name: Move index.php for wp_siteurl
####     when: vccw.wp_siteurl != ''
####     command: "mv /tmp/index.php {{ vccw.document_root }}/index.php"
#### 
####   - name: Create `.gitignore`
####     get_url:
####       url: https://raw.githubusercontent.com/github/gitignore/master/WordPress.gitignore
####       dest: /tmp/.gitignore
####       mode: 0644
####       force: yes
####   - name: Move `.gitignore`
####     command: "mv /tmp/.gitignore {{ path }}/.gitignore"

  - name: Run `wp core language install`
    command: |
      wp core language install {{ vccw.lang }}
      --path={{ path }}
      --skip-themes
      --activate

  # Install Plugins
  - name: Run `wp plugin install`
    command: |
      wp plugin install {{ item }}
      --activate
      --skip-themes
      --path={{ path }}
    with_items: "{{ vccw.plugins | default([]) }}"

  # Install wp-multibyte-patch
  - name: Run `wp plugin install wp-multibyte-patch`
    command: |
      wp plugin install wp-multibyte-patch
      --activate
      --skip-themes
      --path={{ path }}
    when: vccw.lang == 'ja'

  # Check exsist Theme
  - name: Run `wp theme is-installed`
    command: |
      wp theme is-installed {{ vccw.theme }}
      --skip-themes
      --path={{ path }}
    register: theme_is_installed
    ignore_errors: True
    when: vccw.theme != ''

  # Install Theme
  - name: Run `wp theme install`
    command: |
      wp theme install {{ vccw.theme }}
      --skip-themes
      --path={{ path }} --activate
    when: vccw.theme != '' and theme_is_installed.stdout == "1"

  - name: Run `wp theme activate`
    command: |
      wp theme activate {{ vccw.theme }}
      --skip-themes
      --path={{ path }}
    when: vccw.theme != ''

  # Import Theme Unit Test Data
  - name: Run `wp plugin install wordpress-importer`
    command: |
      wp plugin install wordpress-importer
      --skip-themes
      --activate
      --path={{ path }}
    when: vccw.theme_unit_test
  - name: Download WordPress theme unit test data
    when: vccw.theme_unit_test
    get_url:
      url: "{{ vccw.theme_unit_test_uri }}"
      dest: "/tmp/theme-unit-test-data.xml"
  - name: Import WordPress theme unit test data
    when: vccw.theme_unit_test
    command: |
      wp import
      /tmp/theme-unit-test-data.xml
      --authors=create
      --path={{ path }}
      --skip-themes

  # Import Options
  - name: Run `wp options update`
    command: |
      wp option update {{ item.key }} '{{ item.value }}'
      --path={{ path }}
      --skip-themes
    with_dict: "{{ vccw.options }}"

  # Localization
  - name: Get the timezone
    command: |
      wp eval "echo _x( '0', 'default GMT offset or timezone string' );"
      --path={{ path }}
      --skip-themes
    register: timezone
  - name: Update timezone
    command: |
      wp option update timezone_string '{{ timezone.stdout }}'
      --path={{ path }}
      --skip-themes

  - name: Get the date format
    command: |
      wp eval "echo __( 'M jS Y' );"
      --path={{ path }}
      --skip-themes
    register: date_format
  - name: Update date format
    command: |
      wp option update date_format '{{ date_format.stdout }}'
      --path={{ path }}
      --skip-themes

  # Setting Permalink
  - name: Run `wp rewrite structure`
    when: vccw.rewrite_structure != ''
    command: |
      wp rewrite structure {{ vccw.rewrite_structure }}
      --path={{ path }}
      --skip-themes
  - name: Flush rewrite rules
    when: vccw.rewrite_structure != ''
    command: |
      wp rewrite flush
      --hard
      --path={{ path }}
      --skip-themes

 # multisite Settings
  - name: Run `wp core multisite-convert`
    when: vccw.multisite
    command: |
      wp core multisite-convert
      --path={{ path }}
      --skip-themes
  - name: Create `.htaccess` for multisite
    when: vccw.multisite
    template:
      src: templates/multisite-htaccess
      dest: /tmp/.htaccess
  - name: Move `.htaccess` for multisite
    when: vccw.multisite
    command: "mv /tmp/.htaccess {{ vccw.document_root }}/.htaccess"
  - name: Setting up Wordpress multisite options
    command: |
      wp network meta update 1 {{ item.key }} '{{ item.value }}'
      --path={{ path }}
      --skip-themes
    with_dict: "{{ vccw.multisite_options | default({}) }}"
    when: vccw.multisite

  # Generate Movefile
  - name: Check `wp scaffold movefile` exists.
    shell: bash -lc 'wp help scaffold movefile &> /dev/null; echo $?'
    register: is_command
  - stat:
      path: "{{ vccw.vagrant_dir }}/Movefile"
    register: is_movefile
  - name: Create a Movefile
    become: no
    shell: /bin/bash -lc "wp scaffold movefile --force"
    args:
      chdir: "{{ vccw.vagrant_dir }}"
      creates: Movefile
    when: is_command.stdout == "0" and is_movefile.stat.exists != true

{'fraction_non_alphanumeric': 0.1649113270367602, 'fraction_numerical': 0.001630767140042128, 'mean_word_length': 2.1712992889463476, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5088047', 'n_tokens_mistral': 4939, 'n_tokens_neox': 4856, 'n_words': 1254}