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
107
votes
6 answers

How to run Ansible without specifying the inventory but the host directly?

I want to run Ansible in Python without specifying the inventory file through (ANSIBLE_HOST) but just by: ansible.run.Runner( module_name='ping', host='www.google.com' ) I can actually do this in fabric easily but just wonder how to do this in…
Ngoc Tran
  • 1,361
  • 3
  • 11
  • 8
103
votes
8 answers

shell-init: error retrieving current directory: getcwd -- The usual fixes do not wor

I have a simple script: #!/bin/bash for server in $(~/.ansible/ansible_hosts) do ssh $server "hostname; readlink /opt/mydir/mylink;" done It works fine - the program returns the correct hostname and link - except that I get the following error…
Todd Ellner
  • 1,031
  • 2
  • 7
  • 4
102
votes
9 answers

Run an Ansible task only when the variable contains a specific string

I have multiple tasks depend from the value of variable1. I want to check if the value is in {{ variable1 }} but I get an error: - name: do something when the value in variable1 command: when: "'value' in {{ variable1 }}" I'm using…
mndhr
  • 1,409
  • 5
  • 13
  • 17
101
votes
10 answers

How to get an arbitrary remote user's home directory in Ansible?

I can do that with shell using combination of getent and awk like this: getent passwd $user | awk -F: '{ print $6 }' For the reference, in Puppet I can use a custom fact, like this: require 'etc' Etc.passwd { |user| …
Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68
101
votes
14 answers

Missing sudo password in Ansible

Ansible asks for sudo password from following code, it tries to create a new postgres user. Error message: fatal: [xxx.xxx.xxx.xxx] => Missing sudo password main.yml - name: 'Provision a PostgreSQL server' hosts: "dbservers" sudo: yes …
user469652
  • 48,855
  • 59
  • 128
  • 165
99
votes
10 answers

Not possible to source .bashrc with Ansible

I can ssh to the remote host and do a source /home/username/.bashrc - everything works fine. However if I do: - name: source bashrc sudo: no action: command source /home/username/.bashrc I get: failed: [hostname] => {"cmd": ["source",…
pldimitrov
  • 1,597
  • 2
  • 16
  • 21
98
votes
4 answers

How to run apt update and upgrade via Ansible shell

I'm trying to use Ansible to run the following two commands: sudo apt-get update && sudo apt-get upgrade -y I know with ansible you can use: ansible all -m shell -u user -K -a "uptime" Would running the following command do it? Or do I have to use…
nadermx
  • 2,596
  • 7
  • 31
  • 66
96
votes
5 answers

How do I register a variable and persist it between plays targeted on different nodes?

I have an Ansible playbook, where I would like a variable I register in a first play targeted on one node to be available in a second play, targeted on another node. Here is the playbook I am using: --- - hosts: localhost gather_facts: no …
Chris Adams
  • 2,721
  • 5
  • 33
  • 45
93
votes
3 answers

How do I write an Ansible handler with multiple tasks?

In response to a change, I have multiple related tasks that should run. How do I write an Ansible handler with multiple tasks? For example, I would like a handler that restarts a service only if already started: - name: Restart conditionally …
Tim Diels
  • 3,246
  • 2
  • 19
  • 22
92
votes
3 answers

Ansible: create a user with sudo privileges

I have taken over a Ubuntu 14.04 server. It has a user called "deployer" (used with capistrano), and as such, it needs sudo privileges. With this setup, I can log into the server and do stuff like: workstation> ssh deployer@myserver myserver> sudo…
Jay Godse
  • 15,163
  • 16
  • 84
  • 131
92
votes
4 answers

Ansible: How to change active directory in Ansible Playbook?

- name: Go to the folder command: chdir=/opt/tools/temp When I run my playbook, I get: TASK: [Go to the folder] ***************************** failed: [host] => {"failed": true, "rc": 256} msg: no command given Any help is much appreciated.
indolent
  • 3,053
  • 5
  • 23
  • 21
91
votes
22 answers

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 file), view (the file) and nothing works. cat test.yml…
MMT
  • 1,931
  • 3
  • 19
  • 35
90
votes
4 answers

include tasks from another role in ansible playbook

I'm designing a kind of playbook lib with individual tasks so in the usual roles repo, I have something like: roles ├── common │   └── tasks │ ├── A.yml │   ├── B.yml │ ├── C.yml │ ├── D.yml │ ├── login.yml │ ├──…
Louis
  • 1,392
  • 2
  • 11
  • 16
89
votes
7 answers

How can I write variables inside the tasks file in ansible

I have this play.yml --- - hosts: localhost tasks: - include: apache.yml My apache.yml file looks like this: vars: url: http://example.com/apache - name: Download apache shell: wget {{ url }} This is giving me an error. If I…
user1994660
  • 5,253
  • 11
  • 30
  • 33
88
votes
9 answers

Ansible - Print message - debug: msg="line1 \n {{ var2 }} \n line3 with var3 = {{ var3 }}"

In Ansible (1.9.4) or 2.0.0 I ran the following action: - debug: msg="line1 \n {{ var2 }} \n line3 with var3 = {{ var3 }}" $ cat roles/setup_jenkins_slave/tasks/main.yml - debug: msg="Installing swarm slave = {{ slave_name }} at {{ slaves_dir }}/{{…
AKS
  • 16,482
  • 43
  • 166
  • 258