Questions tagged [ansible]

Ansible is an open-source software platform for configuring and managing computers. It combines multi-node software deployment, ad-hoc task execution, and configuration management.

Ansible is an open-source software platform for configuring and managing computers. It combines multi-node software deployment, ad-hoc task execution, and configuration management. It manages nodes over SSH and does not require any additional remote software to be installed on them. Modules work over JSON and standard output and can be written in any programming language. The system uses YAML to express reusable descriptions of systems.

The platform was created by Michael DeHaan, the author of the provisioning server application Cobbler and co-author of the Func framework for remote administration. It is included as part of the Fedora distribution of Linux, owned by Red Hat inc., and is also available for Red Hat Enterprise Linux, CentOS and Scientific Linux via Extra Packages for Enterprise Linux (EPEL) as well as other operating systems. Ansible was commercially supported and sponsored by AnsibleWorks. Since October 2015 Ansible is owned by RedHat.

It was named by DeHaan after the fictional instantaneous hyperspace communication system featured in Orson Scott Card's Ender's Game.

1769 questions
147
votes
2 answers

What's the difference between include_tasks and import_tasks?

In Ansible 2.4, the include module is deprecated. In its place, it ships with two replacement modules, import_tasks and include_tasks. But they have very similar descriptions: include_tasks: Includes a file with a list of tasks to be executed in…
Ben S
  • 1,581
118
votes
7 answers

How to set default Ansible username/password for SSH connection?

I am using Ansible and I have this configuration in my inventory/all: [master] 192.168.1.10 ansible_connection=ssh ansible_ssh_user=vagrant ansible_ssh_pass=vagrant [slave] 192.168.1.11 ansible_connection=ssh ansible_ssh_user=vagrant…
Robert
  • 1,332
101
votes
13 answers

Ansible: Execute task only when a tag is specified

Ansible tags can be used to run only a subset of tasks/roles. This means that by default all tasks are executed and we can only prevent some tasks to execute. Can we limit a task to be exectued only when "foo" tag is specified? Can we use current…
101
votes
3 answers

Adding a user to an additional group using ansible

How can I add a user to additional groups with Ansible? For example, I would like to add a user to the sudo group without replacing the user's existing set of groups.
vdboor
  • 3,880
65
votes
6 answers

Display output with Ansible

I have a Ansible play for PGBouncer that displays some output from a stats module built into PGBouncer. My issue is that when Ansible prints the output to the terminal it mangles the newlines. Instead of seeing ---------- | OUTPUT | ---------- I…
mjallday
  • 922
57
votes
1 answer

how to access host variable of a different host with Ansible?

Let's say I have a host that collects some data and it's in a group [collectors]. I also have hosts in-group [reporters]. So, I want to set a variable on reporters from groups['collectors'][0] IP address. But the playbook for setting up reporters…
hryamzik
  • 827
57
votes
4 answers

Ansible: copy template only when destination file does not exist

I'm using Ansible 1.6.6 to provision my machine. There is a template task in my playbook that creates destination file from Jinja2 template: tasks: - template: src=somefile.j2 dest=/etc/somefile.conf I do not want to replace somefile.conf if it…
51
votes
3 answers

Always trigger handler execution in Ansible

I'm using Ansible to provision my development server. I want it to always start some services for me. I have handlers for this purpose but what is the best way to trigger handler execution without condition, e.g. make it always work? Something like…
46
votes
6 answers

Appending to lists or adding keys to dictionaries in Ansible

(Related to Callbacks or hooks, and reusable series of tasks, in Ansible roles): Is there any better way to append to a list or add a key to a dictionary in Ansible than (ab)using a jina2 template expression? I know you can do something like: -…
Craig Ringer
  • 11,243
28
votes
1 answer

How to assign an empty value to a variable in Ansible?

If firewall_allowed_ports in: - name: port {{ item }} allowed in firewall ufw: rule: allow port: "{{ item }}" proto: tcp with_items: - 22 - "{{ firewall_allowed_ports }}" is undefined, then this error occurs: fatal:…
030
  • 6,011
25
votes
4 answers

How do I add sudo permissions to a user created with Ansible?

What is the cleanest way of doing this? Tried adding the user to the sudo group with the users module but Ansible reports it can't find the sudo group.
Hyperfocus
  • 1,177
21
votes
3 answers

Easiest way to exit Ansible playbook while debugging

Say I'm debugging an Ansible playbook and want to quit after a given task (and not run through all of the following tasks). Is there any one-line magic command available, or do I have to manually create an exit/assert task? From the ansible-playbook…
s g
  • 621
  • 3
  • 9
  • 17
20
votes
4 answers

Ansible change default value according to a condition

Is it possible to change a role variable default value according to some condition (i.e. the value of another variable)? Details I have two related variables for a command, env and composer_opts. If both are left at default (env = "prod" and…
19
votes
8 answers

Ansible: Add IPs from inventory to /etc/hosts of all nodes

I am deploying a small 3 node cluster and I want to add the public IP addresses as defined in my inventory to the /etc/hosts files of all of the nodes. I am trying to use the following, but it is giving me an error: - name: Add IP address of all…
Kevin
  • 847
19
votes
3 answers

Ansible with_items doesn't print whole item?

I'm automatically securing SSL keys like this: - name: Find ssl keys find: paths="/etc/ssl/" patterns="*.key" recurse=yes register: secure_ssl_keys_result - name: Secure ssl keys file: path={{ item.path }} user=root group=root mode=600 …
Zulakis
  • 4,233
1
2 3
27 28