Lately I am working on automating my website creation so that if I want to change my hosting provider. The other thought is to host my site locally on my kubernetes cluster which I am planing to implement in my home. I created an Ansible playbook to automate my WordPress website installation as this a small project with out complexity. This is a kind of backup strategy for the site so I will have latest backup of linuxnix.com site. After almost 3 years later I started using Ansible for this project. I felt Chef and puppet is not that suitable for this.

I written couple of roles for

  1. WordPress software installation
  2. MySQL software installation
  3. Nginx software installation etc.

When I executed my playbook containing these roles I come across below weird error.

root@linuxnix:~# ansible-playbook -i wordpress-setup/hosts wordpress-setup/wordpress-setup.yml

Error:

ERROR! unexpected parameter type in action: <type 'bool'>

The error appears to be in '/root/wordpress-setup/roles/mysql/tasks/main.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Install MySQL software
^ here

Initially I thought it was a linting issue(A kind of file format issue) within in my mysql tasks as it show error above. But after carefully observing I come to know the actual error was with unexpected parameter not with any linting issue from the first line in above error message.

My SQL role file contains:

---
- name: Install MySQL software
apt: name={{ item }} state=present
sudo: yes
with_items:
- mysql-server
- php-mysql
- php
- python-mysqldb
- php-curl
- php-gd
- php-intl
- php-mbstring
- php-soap
- php-xml
- php-xmlrpc
- php-zip
- php-fpm
- php-pear
- php-dev

- name: Start SQL and php-fpm services
service: name={{ item }} state=started
with_items:
- mysql
- php7.2-fpm

After digging for some time I cam across sudo keyword is no more supported from Anisble 2.9. So I have to change my above sudo command to become:. After doing this my Anisble cookbook ran successfully and I am able to create my website.

The new role with become keyword is as below.

---
- name: Install MySQL software
apt: name={{ item }} state=present
become: yes
with_items:
- mysql-server
- php-mysql
- php
- python-mysqldb
- php-curl
- php-gd
- php-intl
- php-mbstring
- php-soap
- php-xml
- php-xmlrpc
- php-zip
- php-fpm
- php-pear
- php-dev

- name: Start SQL and php-fpm services
service: name={{ item }} state=started
with_items:
- mysql
- php7.2-fpm

After updating this, I am able to automate whole website creation.

root@ubuntu-s-1vcpu-1gb-nyc1-01:~# ansible-playbook -i wordpress-setup/hosts wordpress-setup/wordpress-setup.yml

PLAY [wordpress] *************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************

[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host localhost should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release

will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed

in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

ok: [localhost]

TASK [server : Update apt cache] *********************************************************************************************************************************************************************************

changed: [localhost]

TASK [server : Update system] ************************************************************************************************************************************************************************************

changed: [localhost]

TASK [nginx : Install Nginx server] ******************************************************************************************************************************************************************************

ok: [localhost]

TASK [wordpress : Install MySQL software] ************************************************************************************************************************************************************************

[DEPRECATION WARNING]: Invoking “apt” only once while using a loop via squash_actions is deprecated. Instead of using a loop to supply multiple items and specifying `name: “{{ item }}”`, please use `name:

[‘mysql-server’, ‘php-mysql’, ‘php’, ‘python-mysqldb’, ‘php-curl’, ‘php-gd’, ‘php-intl’, ‘php-mbstring’, ‘php-soap’, ‘php-xml’, ‘php-xmlrpc’, ‘php-zip’, ‘php-fpm’, ‘php-pear’, ‘php-dev’]` and remove the loop.

This feature will be removed in version 2.11. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

changed: [localhost] => (item=[u’mysql-server’, u’php-mysql’, u’php’, u’python-mysqldb’, u’php-curl’, u’php-gd’, u’php-intl’, u’php-mbstring’, u’php-soap’, u’php-xml’, u’php-xmlrpc’, u’php-zip’, u’php-fpm’, u’php-pear’, u’php-dev’])

TASK [wordpress : Start SQL and php-fpm services] ****************************************************************************************************************************************************************

ok: [localhost] => (item=mysql)

ok: [localhost] => (item=php7.2-fpm)

TASK [wordpress : WordPresss | Ensure that installation directory exists] ****************************************************************************************************************************************

changed: [localhost]

TASK [wordpress : WordPresss | Download 4.0 to /tmp] *************************************************************************************************************************************************************

changed: [localhost]

TASK [wordpress : WordPresss | Extract archive] ******************************************************************************************************************************************************************

changed: [localhost]

TASK [wordpress : WordPresss | Move extracted directory to /var/site/linuxnix] ***********************************************************************************************************************************

changed: [localhost]

TASK [wordpress : WordPresss | Remove wordpress-4.0.tar.gz] ******************************************************************************************************************************************************

changed: [localhost]

TASK [wordpress : WordPresss | Fetch random salts for wp-config.php] *********************************************************************************************************************************************

[WARNING]: Consider using the get_url or uri module rather than running ‘curl’.  If you need to use command because get_url or uri is insufficient you can add ‘warn: false’ to this command task or set

‘command_warnings=False’ in ansible.cfg to get rid of this message.

changed: [localhost -> localhost]

TASK [wordpress : WordPresss | Copy wp-config.php file] **********************************************************************************************************************************************************

changed: [localhost]

TASK [wordpress : WordPresss | Change ownership of installation directory] ***************************************************************************************************************************************

changed: [localhost]

TASK [wordpress : WordPresss | Change ownership of wp-content directory] *****************************************************************************************************************************************

changed: [localhost]

PLAY RECAP *******************************************************************************************************************************************************************************************************

localhost                  : ok=15  changed=12  unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

 

Hope this helps some one who have come across same issue.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.