Questions tagged [ansible]

On-topic questions are concerned with the use of the tool itself. Installing Ansible and prerequisites, connection issues, ... are off-topic. Red Hat Ansible is a model-driven, configuration management, multi-node deployment/orchestration and remote task execution system. It uses SSH by default, so there is no special software to be installed on the nodes you manage. Ansible is written in Python but can be extended in any language.

Red Hat® Ansible® is a model-driven, configuration management, multi-node deployment/orchestration and remote task execution system. It uses SSH and Python by default, so there is no special software to be installed on the nodes you manage. Simply, it is an agentless configuration management tool. Ansible can be extended in any language, as long as the modules can process and respond with JSON.

The biggest advantage of Ansible over other configuration management technologies is, it is agent-less, i.e., no clients need to be installed, which avoids the chicken and egg problem.

The name "ansible" is taken from the science fiction concept of a machine capable of instantaneous or superluminal communication.

While only a Linux node can be used as a control machine, it remains nonetheless possible to have Windows nodes as a target into Ansible.

Ansible capabilities have gained a lot of modules to cover Infrastructure as a Service, Platform as a Service, and Service as a Service.

Ansible is also capable of interacting with a lot of network equipment like Cisco IOS, Juniper Junos or F5 Bigip.

Ansible has two major products,

  • Ansible Engine - Easily and quickly deploy IT services, applications and environments, remove barriers between IT teams by automating routine activities.

  • Ansible Tower - With Red Hat® Ansible® Tower you can centralize and control your IT infrastructure with a visual dashboard, role-based access control, job scheduling, integrated notifications and graphical inventory management. Easily embed Ansible Tower into existing tools and processes with REST API and CLI.

Relevant links:

Related tags:

23075 questions
84
votes
7 answers

How do I exit Ansible play without error on a condition

I want to exit without an error (I know about assert and fail modules) when I meet a certain condition. The following code exits but with a failure: tasks: - name: Check if there is something to upgrade shell: if apt-get --dry-run…
jreisinger
  • 1,493
  • 1
  • 10
  • 21
84
votes
2 answers

Using Ansible set_fact to create a dictionary from register results

In Ansible I've used register to save the results of a task in the variable people. Omitting the stuff I don't need, it has this structure: { "results": [ { "item": { "name": "Bob" }, …
Phil Gyford
  • 13,432
  • 14
  • 81
  • 143
84
votes
8 answers

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: test_user sudo: yes tasks: - name: Transfer…
Pattu
  • 3,481
  • 8
  • 32
  • 41
83
votes
6 answers

Why is copying a directory with Ansible so slow?

I'm using Ansible to copy a directory (900 files, 136MBytes) from one host to another: --- - name: copy a directory copy: src={{some_directory}} dest={{remote_directory}} This operation takes an incredible 17 minutes, while a simple scp -r…
dokaspar
  • 8,186
  • 14
  • 70
  • 98
82
votes
6 answers

Ansible: How to encrypt some variables in an inventory file in a separate vault file?

The settings Consider an Ansible inventory file similar to the following example: [san_diego] host1 host2 [san_francisco] host3 host4 [west_coast] san_diego san_francisco [west_coast:vars] db_server=foo.example.com db_host=5432 db_password=top…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
80
votes
5 answers

How can I test jinja2 templates in ansible?

Sometimes I need to test some jinja2 templates that I use in my ansible roles. What is the simplest way for doing this? For example, I have a template (test.j2): {% if users is defined and users %} {% for user in users %}{{ user }} {% endfor %} {%…
Alex
  • 5,728
  • 5
  • 20
  • 20
80
votes
3 answers

ansible: include role in a role?

Is it possible to reuse a role in a role? I do not mean via defining a dependency in the meta/main.yml file of a role but by including the role in the tasks/main.yml of another role directly? For example, I define a couple of basic roles in…
Michael
  • 8,357
  • 20
  • 58
  • 86
80
votes
2 answers

Ansible Command module says that '|' is illegal character

I am using Ansible to deploy my project and I trying to check if an specified package is installed, but I have a problem with it task, here is the task: - name: Check if python-apt is installed command: dpkg -l | grep python-apt register:…
Robert
  • 10,403
  • 14
  • 67
  • 117
79
votes
3 answers

How to continue execution on failed task after fixing error in playbook?

When writing and debugging Ansible playbooks, typical workflow is as follows: ansible-playbook ./main.yaml Playbook fails on some task Fix this task and repeat line 1, waiting for all previous tasks to execute again. Which takes a lot of…
Sergey Alaev
  • 1,003
  • 2
  • 8
  • 7
79
votes
4 answers

Ansible - accessing local environment variables

I wonder if there is a way for Ansible to access local environment variables. The documentation references accessing variable on the target machine: {{ lookup('env', 'SOMEVAR') }} Is there a way to access environment variables on the source…
alexs333
  • 12,143
  • 11
  • 51
  • 89
77
votes
4 answers

Ansible - Mode 755 for directories and 644 for files recursively

I'd like to allow anyone to list and read all files in my directory tree, but I don't want to make the files executable : dir \subdir1 file1 \subdir2 file2 ... \subdirX fileX The following task makes my directories and…
mykola
  • 1,038
  • 2
  • 8
  • 14
77
votes
9 answers

Ansible playbook shell output

I would like to quickly monitor some hosts using commands like ps,dstat etc using ansible-playbook. The ansible command itself perfectly does what I want, for instance I'd use: ansible -m shell -a "ps -eo pcpu,user,args | sort -r -k1 | head…
stijn
  • 34,664
  • 13
  • 111
  • 163
76
votes
4 answers

Difference between shell and command in ansible

I am new to the Ansible world can anyone help me in understanding the difference between shell and command in Ansible? When to use shell and when to use command? I know that the command module is safer, as it is not affected by the user's…
prashant
  • 2,808
  • 5
  • 26
  • 41
76
votes
4 answers

Ansible: How to chmod +x a file with Ansible?

What is the best way to chmod + x a file with ansible. Converting the following script to ansible format. mv /tmp/metadata.sh /usr/local/bin/meta.sh chmod +x /usr/local/bin/meta.sh This is what I have so far.. - name: move /tmp/metadata.sh to…
Atlantic0
  • 3,271
  • 5
  • 17
  • 24
76
votes
1 answer

How to force handler to run before executing a task in Ansible?

I have a playbook which should configure on specified IP, and than connect to this app to configure stuff inside. I've got a problem: I need to restart app after I've changed anything in app config, and if I do not restart app, connection to it…
George Shuklin
  • 6,952
  • 10
  • 39
  • 80