Adding Custom Ansible Role - Zend Loader

Hi there. This is my first time making my own custom Ansible Role inside of Bedrock, and I’m running into some issues, and was hoping I could get some help.

I made a new role using galaxy-ansible, and added the following items:

To my php.ini file under the php role, I added this:

ZendGuardLoader_path: /srv/www/domain/zend/zend-loader-php5.6-darwin10.7-x86_64/ZendGuardLoader.so
ZendGuardLoader_opcache_path: /srv/www/domain/zend/zend-loader-php5.6-darwin10.7-x86_64/opcache.so
ZendGuardLoader_enabled: 1
ZendGuardLoader_licensing: 0

Under my zend role, I added to defaults/main.yml': ZendGuardLoader_version: '7.0.0'
In tasks/main.yml I added:

- name: Download Zend
  get_url: >
   url=http://downloads.zend.com/guard/{{ ZendGuardLoader_version }}/zend-loader-php5.6-darwin10.7-x86_64.tar.gz
   dest=/srv/www/domain/zend/zend-loader-php5.6-darwin10.7-x86_64.tar.gz

- name: Extract and install Zend
  unarchive: src=/srv/www/domain/zend/zend-loader-php5.6-darwin10.7-x86_64.tar.gz
             dest=/srv/www/domain/zend/
             copy=no

This all worked correctly. It download the latest version (7.0.0), copied it to the correct directory, added the lines to php.ini and ran the provision correctly. However, the permissions are -rwxrwxrwx 1 nobody nogroup.

So, couple of questions:

  1. How do I not hardcode /srv/www/domain? I tried using dest="{{ www_root }}/{{ item.key }}/zend/ but got an item can not be found error, or something like that.
  2. How do I make the directory zend with Ansible? To get this to work, I had to manually ssh into vagrant, and create the folder, and change the ownership using sudo. So, there is something I am doing wrong.
  3. How do I set appropriate permissions?
  4. Use variables instead of hardcoding links in php.ini

Did a lot of cool stuff!

tasks/main.yml

- name: Create Zend Folder
  file: path="{{ zend_path }}"
        owner="{{ web_user }}"
        group="{{ web_group }}"
        mode=0755
        state=directory

- name: Download Zend
  get_url: >
   url="{{ zend_url }}"
   dest="{{ zend_path }}/{{ zend_zip }}"

- name: Extract and install Zend
  unarchive: src="{{ zend_path}}/{{ zend_zip }}"
             dest="{{ zend_path}}"
             copy=no

- name: Delete Downloaded zip file
  file: path="{{ zend_path }}/{{ zend_zip }}"
        state=absent


- name: Change Zend folder to user
  file: path="{{ zend_path }}"
        owner="{{ web_user }}"
        group="{{ web_group }}"
        state=directory
        recurse=yes

defaults/main.yml

ZendGuardLoader_version: '7.0.0'
zend_zip: "zend-loader-php5.6-darwin10.7-x86_64.tar.gz"
zend_url: "http://downloads.zend.com/guard/{{ ZendGuardLoader_version }}/{{ zend_zip }}"
zend_path: "/srv/www/domain/zend"

Only thing I need to figure out now is how to use {{ www_data }} {{ item_key}} instead of using a hardcoded path to my /srv/www/domain and how to prevent using hardcoded urls in php.ini as well!

{{ www_root }} will work fine on its own. {{ item_key}} only works in the context of looping over wordpress_sites via with_dict (search for that in the repo to see how it’s used).

1 Like

Using {{ www_root }} gave me /srv/www/zend instead of /srv/www/domain/zend which I had tried earlier, and assumed {{ item.key }} was the domain.

Looking through it, I’m not yet able to find the logic that handles {{ item.key }}, or I can loop through it.