How Do You Troubleshoot an Ansible Playbook Failing with “The filter … is invalid…AttributeError: Client Error object has no attribute message”?

Problem scenario
Your playbook fails with the following message: “The filter … is invalid…AttributeError: Client Error object has no attribute message”?

What should you do?

Solution
Remove the word “filter” and try your playbook again.

 » Read more..

How Do You Use Ansible to Have Retrievable Double Quotes ‘”‘ in a Variable?

Problem scenario
You are using Ansible, and you want a playbook to have a variable with double quotes. The double quotes are disappearing from your echo var1.stdout[:] invocations. How do you get shell/bash commands to have double quotes?

Solution
Rather than “echo” a string with double quotes, use a variable assignment. Do not use this: echo “a \”long string\” for a \”test\” “

Use something like this: coolstring=”a \”long string\” for a \”test\” ” &&

 » Read more..

How Do You Fix the Stack Storm Error “Failed to authenticate”?

Problem scenario
You run an st2 command, but it fails with an error like this:

Failed to authenticate with credentials provided in the config.
ERROR: 401 Client Error: Unauthorized
MESSAGE: Invalid or missing credentials for url: http://127.0.0.1:9100/tokens

What should you do?

Solution
Run a command like this (but replace “jdoe” and “passwordhere” with your credentials respectively):

st2 login jdoe –password ‘passwordhere’

Now run the st2 command(s).

 » Read more..

How Do You Troubleshoot the Error “unexpected EOF while looking for match `\”‘”?

Problem scenario
You run a Bash command or an Ansible playbook, but you get stymied by this problem: “unexpected EOF while looking for match `\”‘”

What should you do when you see this message?

Solution
Verify your escape characters have a space after the symbol that they are escaping.

For example, if you have \””

change it to \” “

The escape character may be working on two sequential symbols (without a space).

 » Read more..

What Is the Syntax for Viewing ec2_instance_info Return Values in Ansible?

Problem scenario
You read about a supported data type (defined keys) in Ansible playbooks related to EC-2 servers in AWS. How do you view this data?

Solution

  1. Have a playbook (.yaml file) with the following syntax:

ec2_instance_info:
region: us-west-1
register: vara

  1. Refer to vara as a variable. Here is an example of how to see it:

debug:
msg: “{{ item.instance_id }}”
loop: “{{ vara.instances }}”

 » Read more..

How Do You Troubleshoot the Ansible Error “block is not a valid attribute for a Play”?

Problem scenario
You run an ansible-playbook command but you receive “‘block’ is not a valid attribute for a Play.” What should you do?

Solution
Change the word “block” to “tasks” in your playbook.

 » Read more..

How Do You Change the Version of Python that Ansible Uses?

Problem scenario
You are using Ansible with -vvv to see what Python version it is using. (Or you use ansible –version.) You see an incorrect version of Python being used.

You tried ansible_python_interpreter=/usr/bin/python3 in your playbook and in the ansible.cfg file. Neither worked.

What should you do?

Solution
In the playbook, find the hosts stanza. Underneath it use this (where python3 is the version you want and “/usr/bin” is the path to it):

vars:
ansible_python_interpreter: /usr/bin/python3  » Read more..

How Do You Fix the Ansible Problem about “libselinux-python”?

Problem scenario
You try to run an Ansible playbook, but you get an error like this: “msg: Aborting target uses selinux but python bindings (libselinux-python) aren’t installed!”

You are using a Red Hat derivative of Linux (e.g., Red Hat Enterprise Linux, CentOS or Fedora) and Python 3. What should you do?

Solution
Prerequisite

Install pip3. If you need assistance,

 » Read more..

How Do You Troubleshoot Ansible Errors about SELinux?

Problem scenario
You have Python 3 installed, but you do not have pip3 installed. One of the following also apply to your situation:

Problem scenario #1
You run an Ansible playbook. You receive the error message “Aborting, target uses selinux but python bindings (libselinux-python) aren’t installed.”

Problem scenario #2
You run an Ansible playbook.

 » Read more..

How Do You Troubleshoot the “aws ssm” Command Failing with a Message about “InvalidInstanceId”?

Problem scenario
In AWS Systems Manager you run an “aws ssm” command. You get “An error occurred (InvalidInstanceId) when calling the Send Command operation.” What should you do?

Solution
Are there spaces or braces inside the double quotes? These symbols are not part of the instance ID. If you are running a script or complex command, extraneous symbols may be getting injected into your instance ID.

 » Read more..