How Do You Troubleshoot the Ansible Error “Only one –vault-id can be used for encryption.”?

Problem scenario
You try to run ansible-vault, but you get this error:
“ERROR! Only one –vault-id can be used for encryption.  This includes passwords from configuration and cli.”  You want a fast solution, and you have complete control of the Ansible server. You do not need to use encryption or decryption for your Ansible operation(s).  What should you do?

Solution
Modify the ansible.cfg file.

How Do You Get ansible-vault to Prompt You for a Password to Encrypt a File That You Create?

Problem scenario
You are using the ansible-vault command.  You are not being prompted for a password as the documentation suggests you would be.  You want to use ansible-vault create or ansible-vault edit and be prompted for a password. How can you specify a password manually?  How can someone on a different Ansible server decrypt your encrypted files?  

Possible solution #1
Modify the ansible.cfg file.

How Do You Prepend or Append to a Variable in Ansible?

Problem scenario
You are using a variable in Ansible.  You want to attach a string to it to augment this variable.  You can rename it so later in the playbook you can call this modified, augmented version of the variable.

You assign the variable like this:

foo: ” {{ bar }}”

You want foo to have an extra string (e.g., “/subdirectory/path/to”).  What do you do?

How Do You Leverage Ansible to Deploy Salt Minion to an Ansible Managed Node?

Problem scenario
You have two configuration management servers: one is an Ansible control server and another is a Salt Master server.  You want Ansible to deploy Salt Minion to the managed nodes.  You want the managed nodes of Ansible to receive configurations from the Salt Master server.  This way one team can use SaltStack and another team can use Ansible.  How do you do this?

Solution

Prerequisites
This assumes you have deployed Salt Master and Ansible

How Do You Get Ansible Playbooks to Create Directories on Managed Nodes?

Problem scenario
You want Ansible to create directories on managed nodes.  How do you write a playbook to do this?

Solution
Prerequisites

This assumes that you have installed and configured Ansible.  If you do not know how to deploy Ansible, see this posting if you are using a Red Hat derivative.  If you are using Linux SUSE,

How Do You Run an Ansible Playbook to Configure 2 GB of Swap Space on Every Linux Server?

Problem scenario
You want every Linux server to have 2 GB of virtual memory.  You want to transfer a Bash script to each server and run it with sudoer privileges.  How do you transfer a file and execute it as a sudoer user?

Solution
1.  Install Ansible.  If you need directions on how to do this with RHEL, see this posting.  For SUSE,

How Do You Run Ansible Playbooks on Managed Nodes That Run Shell Scripts That Require sudo?

Problem scenario
You run an Ansible playbook on a server as a remote user that is a sudoer on that same server.  But you get this error when you run the playbook: “sudo: a password is required\r\n”, “msg”: “MODULE FAILURE”, “rc”: 1}”   How do you troubleshoot this error?

You want to run Bash scripts via Ansible playbooks.  But these scripts will install packages and modify sensitive files. 

How Do You Set up Ansible for the First Time?

Problem scenario
You have Ansible installed as a control server (a centralized server to push down configurations to other servers).  You want to use it to manage another server.  How do you configure the other server to be a managed node?  In other words, how do you configure Ansible to push configuration changes down to servers?

Solution
Prerequisite
Ansible must be installed.

How Do You Troubleshoot the Ansible Message ‘Error while linking: [Errno 2] No such file or directory … “state”: “absent”‘?

Problem scenario
You are using the file module in Ansible.  But you get the error ‘Error while linking: [Errno 2] No such file or directory … “state”: “absent”‘.

What should you do?

Solution
Some people get this problem with different versions of Ansible 2.x.  It is documented on this external page.

Rewrite your Ansible playbook so it uses a “shell” module and some “ln -s” command.

How Do You Fix the Ansible Problem “Failed to connect to the host via ssh: percent_expand: unknown key %C\r\n”, “unreachable”: true”?

Problem scenario 
When you run an Ansible playbook on the control node that is not running on a Mac (e.g., you are running Ansible on RedHat, Ubuntu or SUSE), you get this error: “Failed to connect to the host via ssh: percent_expand: unknown key %C\r\n”, “unreachable”: true”.   How do you debug your playbook to get it to run?

Root cause
​The problem may not be in the playbook.