How to execute a shell script on a remote server using Ansible?

I am planning to execute a shell script on a remote server using Ansible playbook. blank test.sh file: touch test.sh Playbook: --- - name: Transfer and execute a script. hosts: server user:...

Syntax error in for loop (Ruby/RSpec)

While running the RSPEC test as shown below im getting this error: Using Accessor#strict_set for specs SyntaxError:...

ansible answers to mysql_secure_installation

I can't realize how to write a task, that answers mysql_secure_installation script questions. I only have shell: mysql_secure_installation <<< '1111' executable=/bin/bash and no ideas on how to...

Conditionally define variable in Ansible

I want to conditionally define a variable in an Ansible playbook like this: my_var: "{{ 'foo' if my_condition}}" I would like the variable to remain undefined if the condition does not resolve to...

Ansible: enforce pipefail

Earlier today, we experienced a nasty issue that was caused by the following shell pipe: - name: get remote branches shell: git ls-remote -h [email protected]:orga/repo.git | sed...

Jinja2 filter list using string contains test

I'm trying to filter a list in ansible in Jinja2 when the elements contain a string, but the Jinja documentation doesn't seem clear enough for me to figure it out. This is what I have so far: -...

Pass command line arguments to Docker with Ansible

I have a Java socket application that requires a port number as a CLI argument. On my local machine I can run it via: docker run -d -p 1111:1111 --name <name> --link <link> <foo>/<bar> 1111 The...

How to install a Python version on server using Ansible

I am using ansible to connect with server. But I am getting errors for certain pip packages because of older version of python. How can I install a specific version of python (2.7.10) using...

Ansible: "Failed to connect to the host via ssh" error

I'm trying to get set up with Ansible for the first time, to connect to a Raspberry Pi. Following the official 'getting started' steps, I've made an inventory file: 192.168.1.206 .. but the...

Ansible nested loop cross list reference?

I'm trying to solve this and frankly I'm beggining to think it doesn't work that way. - name: Create directories file: path: "{{ item[0] }}" state: directory owner: some_user ...

Ansible - how to remove an item from a list?

I'd like to remove an item from a list, based on another list. "my_list_one": [ "item1", "item2", "item3" ] My second list: "my_list_two": [ "item3" ] How do I remove 'item3' from this...

Prevent ansible from parsing strings when passed through with_items

I'm trying to use with_items to specify a list of key/value pairs to be passed to a custom ansible module. Problem arises when key or value string has list-like format. E.g., "[('a', 'b'), ('c',...

Ansible - Play with hosts in order I desire

When running a playbook Ansible randomly sets a node as first, second and third. ok: [node-p02] ok: [node-p03] ok: [node-p01] Q: How can I configure Ansible to let it execute with the hosts in...

How to decrypt string with ansible-vault 2.3.0

I have been waiting for ansible 2.3 as it was going to introduce encrypt_string feature. Unfortuately I'm not sure how can I read the encrypted string. I did try decrypt_string, decrypt (the...

Ansible Tower REST API: Is there any way to get the logs/output of a job?

I have a Ansible job started by another Process. Now I need to check the status of the current running job in Ansible Tower. I am able to track the status whether it is...

get command output of container using ansible docker_container module

I'd like using ansible docker_container to generate influxdb config file. which will act the same as below docker command docker run --rm influxdb influxd config >...

Ansible dynamic inventory for Azure VM with private IP only

On Azure I've got a resource group with 1 vnet containing 2 servers; master and worker. Only master has a public IP. Using "plain" Ansible I can manage both servers by defining worker's private IP...

Can an Ansible inventory include another?

We have a set of servers shared between different instances of an application and would like the list of them to be a separate file, with other -- instance-specific inventories -- including it. (I...

How to add disk to VMware's VM host more efficiently by using Ansible offical module?

Env OS Version: CentOS 7.5 Ansible Version: 2.8.4 with python 2.7.5 ESXi and VCenter Version: 6.5.2 Purpose I have already completed my code, but I wondering if there are more better way to add...

Issue looping on block module for a set of tasks in Ansible

I need to check if deploy.db file exists. If it does not exist, then I need to perform a set of tasks for which I'm using block. Below is how i run the playbook ansible-playbook test.yml -e...

Ansible Playbook: How to run Play based on when condition?

I have a playbook with multiple plays. Here is what it looks like: - name: Play A hosts: localhost roles: - do task to get either B or C - name: Play B hosts: Host B roles: - do...

libselinux-python bindings and ansible

Sorry for answering my own question, but I've seen this crop up in multiple forums, so I wanted to post this in hope it helps someone else. The basic problem occurs when trying to run Ansible...

Does Ansible shell module need python on target server?

I have a very basic playbook that simply runs a script using the shell module on the target remote host. In the output it however fails stating python interpreter not found. Installing python on...

Failed to import the required Python library (botocore or boto3)

I'm running a playbook on localhost, and I've already installed ansible and the required packaged like boto3. The playbook works fine when it is performing tasks on a remote host, but outputs the...

ssm-state manager-ansible playbook

I am executing a ansible playbook for ops manager installation in ssm. Issues: Ansible is using python2. how to make it to use python 3? --Output truncated--- ----------ERROR------- Installing...

Tower: What is causing "[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details"

I am just starting to work with Ansible Tower and made a project and then a job template under that project that uses a small initial test playbook (Test.yml): --- - hosts: east01.xxxxx.com ...

Broken package installation using Ansible on debian 11 Bullseye

I woud like to install debian packages using Ansible 2.7.7 on Debian testing (yet) I try to execute this simple task: tasks: - name: install basic packages apt: name: ['mc', 'htop',...

Ansible cannot pickle 'module' object

Running the playbook with $ ansible-playbook test-playbook.yml Getting error response ERROR! Unexpected Exception, this is probably a bug: cannot pickle 'module' object Also have tried shell:...

Flyway - Create users with password in the postgres database using flyway by referring username and password from AWS ssm parameter and secrets manage

I am currently using ansible to create users with password in the AWS postgres database by referring the username and password stored in ssm parameter and secrets manager respectively. We are...

ansible playbook error was: ModuleNotFoundError: No module named 'azure.mgmt.monitor.version' although the module is installed

After upgrading ansible to version 2.10.5 and python3.8.10 my playbook.yml fails with this error. ModuleNotFoundError: No module named 'azure.mgmt.monitor.version' fatal: [localhost]: FAILED! =>...