How Do You Do Variable Expansion with an Ansible Playbook without Introducing Punctuation?

Problem scenario
You use a variable in an Ansible playbook. The value of the variable is surrounded by quotes and brackets. You may refer to it as punctuation [“”]. You want to assign the variable without the new symbols such as ‘[“”]’. How do you get just the value and no punctuation?

Solution
Do not use quotes or square brackets “[]” around the variable.

 » Read more..

How Do You Troubleshoot an Ansible Playbook That Has No Visible Errors when It Runs?

Updated 1/19/19

Problem scenario
An Ansible playbook appears to run with no errors or explicit failures.  But the playbook is not working as you expect.  There is no message indicating what could be wrong.  What should you do to troubleshoot it so the intended effect(s) will happen? 

Tips and Possible Solutions in Nearly Random Order
1.  When you run the ansible-playbook command,

 » Read more..

How Do You Troubleshoot the Ansible Message “Syntax Error while loading YAML. expected , but found ””?

Problem scenario
You run an Ansible playbook with a variable. But you get this message:
“ERROR! Syntax Error while loading YAML. expected , but found ””

How do you get the playbook to run?

Solution
Notice the “offending line” in the message. Remove the braces and possibly the quotes around the braces. Assign the variable by itself (without the braces syntax).

 » Read more..

What Do You Do when an Ansible Playbook is Not Getting a Variable Assigned Properly?

Problem scenario
Ansible variables are not being picked up when the playbook runs. You may get no errors, or you may get errors like these:

“ERROR! Syntax Error while loading YAML…did not find expected key”

“ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path”

What should you do?

Possible Solution #1
Are you using the -i flag when you are running the command to execute the playbook?

 » Read more..

How Do You Transform an Ansible Playbook into a Role?

Problem scenario
You want to refactor a playbook into a role. How do you do this?

Solution

  1. A role will be in a “roles” directory. Create the directory as such.
  2. Take your playbook (.yml or .yaml file) and eliminate the word “tasks” from it. The role should still be in the .yml or .yaml format.
  3. Variables must be extracted.

 » Read more..

How Do You Get an Ansible Variable to Not Add Single Quotes or Brackets when the Variable Is Substituted?

Problem scenario
You are using an Ansible-supported method of a variable in a playbook. This variable will substitute a string or line number that the playbook is run on with the IP address of the host. You notice that this substitution includes an opening-and-closing single quote mark “‘” and a pair of opening-and-closing brackets “[]”. That is, single quotes and brackets are being introduced into the string you want to build with the Ansible playbook.

 » Read more..

How Do You Troubleshoot This Ansible Message “module_stderr…Shared connection to server closed. [Errno 13] Permission denied…MODULE FAILURE”?

Problem scenario
You try to run an Ansible playbook, but you get this problem:

“module_stderr…Shared connection to server closed. [Errno 13] Permission denied…MODULE FAILURE”

How do you fix it?

Solution
Is the Ansible playbook configuring the mode settings to not allow other users to execute the file? It could be that lower in the Ansible playbook, after the file is protected from other users executing it,

 » Read more..

How Do You Write an Ansible Playbook to Retrieve Files from a Directory Relative to where the .YAML File Is?

Problem scenario
You want to refer to files in a subdirectory of the parent directory that houses your Ansible playbook. You have Git repositories with .yaml files and subdirectories. You want the Git repo to be transferred to a variety of different servers. The absolute path to the directory where the files are will vary. How do you have a variable or relative path reference in the playbook so as long as the directory structure is in place,

 » Read more..

How Do You Troubleshoot the Ansible Playbook Error Associated with “[Errno 2] No such file or directory”?

Problem scenario
When running an Ansible playbook using the java_cert module you receive an message “[Errno 2] No such file or directory”. How do you fix this?
(If you were using a file linking step in the playbook and not the java_cert module, see this posting.)

Solution
Use the “executable” attribute of the java_certs module (https://docs.ansible.com/ansible/latest/modules/java_cert_module.html) to specify the full path of the keytool file.

 » Read more..

How Do You Troubleshoot the Ansible Error “directory was skipped as it does not seem to be a valid directory or it cannot be accessed”?

Problem scenario
You are using Ansible’s find module.  You want it to find the destination of a symbolic link.  When you run the playbook you have a way of finding what the find module returns.  It is saying something about “directory was skipped as it does not seem to be a valid directory or it cannot be accessed.”  What should you do?

Solution
Use the stat module. 

 » Read more..