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
184
votes
3 answers

How to get the host name of the current machine as defined in the Ansible hosts file?

I'm setting up an Ansible playbook to set up a couple servers. There are a couple of tasks that I only want to run if the current host is my local dev host, named "local" in my hosts file. How can I do this? I can't find it anywhere in the…
Tanner Semerad
  • 12,472
  • 12
  • 40
  • 49
183
votes
7 answers

How to do multiline shell script in Ansible

right now I am using a shell script in ansible that would be much more readable if it was on multiple lines - name: iterate user groups shell: groupmod -o -g {{ item['guid'] }} {{ item['username'] }} ....more stuff to do with_items: "{{ users…
Subtubes
  • 15,851
  • 22
  • 70
  • 105
168
votes
4 answers

How to run a task when variable is undefined in ansible?

I am looking for a way to perform a task when Ansible variable is not registers or undefined. E.g.: - name: some task command: sed -n '5p' "{{app.dirs.includes}}/BUILD.info" | awk '{print $2}' when: (! deployed_revision) AND (…
sakhunzai
  • 13,900
  • 23
  • 98
  • 159
163
votes
9 answers

Ansible - Use default if a variable is not defined

I'm customizing linux users creation inside my role. I need to let users of my role customize home_directory, group_name, name, password. I was wondering if there's a more flexible way to cope with default values. I know that the code below is…
Bernardo Vale
  • 3,224
  • 4
  • 21
  • 34
163
votes
8 answers

What's the easy way to auto create non existing dir in ansible

In my Ansible playbook many times i need to create a file: - name: Copy file template: src: code.conf.j2 dest: "{{ project_root }}/conf/code.conf" Many times conf dir is not there. Then I have to create another task to create that dir…
user1994660
  • 5,253
  • 11
  • 30
  • 33
161
votes
12 answers

Ansible: get current target host's IP address

How do you get the current host's IP address in a role? I know you can get the list of groups the host is a member of and the hostname of the host but I am unable to find a solution to getting the IP address. You can get the hostname by using…
SJC
  • 2,767
  • 4
  • 20
  • 31
160
votes
5 answers

How do you stop Ansible from creating .retry files in the home directory?

When Ansible has problems running plays against a host, it will output the name of the host into a file in the user's home directory ending in '.retry'. These are often not used and just cause clutter, is there a way to turn them off or put them in…
Asfand Qazi
  • 6,586
  • 4
  • 32
  • 34
160
votes
6 answers

Variable that has the path to the current ansible-playbook that is executing?

Is there an Ansible variable that has the absolute path to the current playbook that is executing? Some context: I'm running/creating an Ansible script against localhost to configure a MySQL Docker container and wanting to mount the data volume…
Josh Unger
  • 6,717
  • 6
  • 33
  • 55
159
votes
14 answers

How to automatically install Ansible Galaxy roles?

All my Ansible playbooks/roles are checked in to my git repo. However, for Ansible Galaxy roles I always have to explicitly download them one by one on every machine I want to run Ansible from. It's even tough to know in advance exactly which…
pdeva
  • 43,605
  • 46
  • 133
  • 171
157
votes
6 answers

How to set host_key_checking=false in ansible inventory file?

I would like to use ansible-playbook command instead of 'vagrant provision'. However setting host_key_checking=false in the hosts file does not seem to work. # hosts file vagrant ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key…
mbdev
  • 6,343
  • 14
  • 46
  • 63
151
votes
12 answers

Override hosts variable of Ansible playbook from the command line

This is a fragment of a playbook that I'm using (server.yml): - name: Determine Remote User hosts: web gather_facts: false roles: - { role: remote-user, tags: [remote-user, always] } My hosts file has different groups of servers,…
luqo33
  • 8,001
  • 16
  • 54
  • 107
150
votes
7 answers

How to set Linux environment variables with Ansible

Hi I am trying to find out how to set environment variable with Ansible. something that a simple shell command like this: EXPORT LC_ALL=C tried as shell command and got an error tried using the environment module and nothing happend. what am I…
Gleeb
  • 10,773
  • 26
  • 92
  • 135
147
votes
10 answers

How to create an empty file with Ansible?

What is the easiest way to create an empty file using Ansible? I know I can save an empty file into the files directory and then copy it to the remote host, but I find that somewhat unsatisfactory. Another way is to touch a file on the remote…
dokaspar
  • 8,186
  • 14
  • 70
  • 98
144
votes
3 answers

Specifying ssh key in ansible playbook file

Ansible playbook can specify the key used for ssh connection using --key-file on the command line. ansible-playbook -i hosts playbook.yml --key-file "~/.ssh/mykey.pem" Is it possible to specify the location of this key in playbook file instead of…
Brian
  • 12,145
  • 20
  • 90
  • 153
143
votes
15 answers

Copy multiple files with Ansible

How can I copy more than a single file into remote nodes by Ansible in a task? I've tried to duplicate the copy module line in my task to define files but it only copies the first file.
Mark K.
  • 1,969
  • 2
  • 16
  • 15