Ansible stat module

I use the Ansible stat module mostly for conditional statements.

For example, only when directory /var/www/phpmyadmin does not exist include the task for installing PHPMyAdmin.

Only when <directory> exists; <do this>

But of course, there are a lot of other uses for this module then the one I use most.

It does this by doing the following two things:

  1. get all system-information about the directory
  2. execute statement, depending on values from the fetched system-information

But there are a lot of uses for the stat module.

The official documentation for the stat module is on, ofcourse, the Ansible website: http://docs.ansible.com/ansible/stat_module.html

full example

# file: install.yml

# install PHPMyAdmin when it's not installed already
- name: PHPMyAdmin | check the need for installment
  stat:
    path: /var/www/html/phpmyadmin
  register: pma

# Only include the PHPMyAdmin installation-task when it's not installed yet
# e.g. the directory /var/www/html/phpmyadmin does not exist
- include: PHPMyAdmin | install
  when: pma.stat.isdir is not defined

As you can see, we’re checking against the variable pma which holds the stats information for our path /var/www/html/phpmyadmin. This variable holds a lot more then just the isdir property.

The full list of information returned by the Ansible stat module:

  • atime
  • attributes
  • charset
  • checksum
  • ctime
  • dev
  • executable
  • exists
  • gid
  • gr_name
  • inode
  • isblk
  • ischr
  • isdir
  • isfifo
  • isgid
  • islnk
  • isreg
  • issock
  • isuid
  • lnk_source
  • md5
  • mime_type
  • mode
  • mtime
  • nlink
  • path
  • pw_name
  • readable
  • rgrp
  • roth
  • rusr
  • size
  • uid
  • wgrp
  • woth
  • writeable
  • wusr
  • xgrp
  • xoth
  • xusr

I will continue to update this page as needed.

Ansible lineinfile module: unsupported parameter for module: path

Is Ansible giving you the error unsupported parameter for module: path when you’re using lineinfile?

Check your Ansible-version!

You probably used path (as of version 2.3) instead of dest.

$ ansible --version
ansible 2.2.1.0
  config file =
  configured module search path = Default w/o overrides

As the Ansible documentation states:

As of Ansible 2.3, the dest option has been changed to path as default, but dest still works as well.

Solution: change dest into path

This fixed it for me. Now I can ensure composer is in my path.

# file composer.yml

# add composer to $PATH
- lineinfile:
    regexp: 'export PATH=".*/project/vendor/bin.*"'
    line: 'export PATH="$PATH:/project/vendor/bin"'
    state: present
    dest: /home/vagrant/.bashrc

Explanation of the parts:

  • regexp: the regular expression to look for. The line that matches will be used for present or absent
  • line: this is the line that will be inserted/replaced into the file
  • state: whether or not line should be there. Tip: for advanced usage, look at backrefs for changing parts of the line.
  • dest: the file we want the line in

See the official documentation for more information.

Behat 3 + Mink + Selenium

Installation

We will be installing the following:

  • Behat version 3 – the testingframework
  • Mink – for controlling real webbrowsers to run your tests
  • PHPUnit – for using the handy ‘assert’ methods PHPUnit provides.
  • Selenium Standalone Server – this will act as a service to accept connections and map them to browsers.

Continue reading

PHP won’t show any errors, or just a blank page

Getting a white page (the infamous the white page of death) when you instruct your browser to open your website? Want to debug an error, but you don’t see error messages on the screen but you do in your logfiles?

Then you should enable the displaying of errors in PHP.

There are few ways you can do this. But the best (fool proof) way is to have this in your php.ini file:

; file /etc/php5/apache2/php.ini

; here goes other settings

display_errors = On

NB: Don’t forget to restart your webserver after changing PHP’s configuration for it to have effect: sudo service apache2 restart

Continue reading

Certified PHP developer – yet again!

Today I got certified for the Zend Certification PHP Engineer exam! My third ZCE certificate in a row!

Zend is the company behind the certification for the PHP scripting language and the Zend PHP-framework.

I am now certified for PHP version 5.5 (there was no 5.6 certification). Before that I passed the exams for PHP version 5.3 in 2013 and version 5 in 2007. And does that make me happy!

A new entry in the ZCPE Directory (formerly known as Zend Yellow Papers) has been reserved for me 🙂

Continue reading

1 3 4 5
>