Friday, September 30, 2016

MongoDB "root" Role

To perform functions such as replication administration, the "dbAdminAnyDatabase" role is not enough. The "root" role is required".
db.grantRolesToUser("admin",[{role:"root","db":"admin"}])

Reference: http://stackoverflow.com/questions/23943651/mongodb-admin-user-not-authorized

Ansible Move File/Folder in Idempotent Manner

Solution is to use conditionals:

       - name: stat the dest path
         stat: path=/path/dest
         register: statdest
       - name: move file
         command: mv /path/src /path/dest
         when: statdest.stat.exists == false

Reference: http://stackoverflow.com/a/24165405/548272

Thursday, September 1, 2016

Bash: Easy Way to Tokenize Strings Separated by Space

Using the "set" command, it is possible to replace the position parameters with the one assigned. This can then be used to refer to individual elements of a string separated by space.

$ str="one two three"
$ set -- $str
$ echo $1
one
$ echo $2
two
$ echo $3
three

Reference: http://stackoverflow.com/questions/5382712/bash-how-to-tokenize-a-string-variable

Ansible Relative Path with playbook_dir

The playbook_dir resolves to the directory where the playbook file resides. You can use relative path from there to reference other files.

Ansible Variables

Good resource about variables which compiles all the different ways variables are used in Ansible: https://liquidat.wordpress.com/2016/01/26/howto-introduction-to-ansible-variables/

Ansible Variables from File

In the task e.g.
- hosts: appservers
 vars_files:
       - vars.yml

vars.yml e.g.:
var1Name: var1Value
var2Name: var2Value
var3Name: var3Value

References: