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.

Filter by
Sorted by
Tagged with
256 votes
6 answers
584k views

How to see stdout of ansible commands?

How do I see stdout for ansible-playbook commands? -v only shows ansible output, not the individual commands. It would be great if I could figure out how to do this immediately, so if something ...
QuinnBaetz's user avatar
  • 2,669
144 votes
2 answers
133k views

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 ...
Ben S's user avatar
  • 1,551
123 votes
8 answers
55k views

How can I implement ansible with per-host passwords, securely?

I would like to use ansible to manage a group of existing servers. I have created an ansible_hosts file, and tested successfully (with the -K option) with commands that only target a single host ...
supervacuo's user avatar
  • 1,433
116 votes
7 answers
497k views

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 ...
Robert's user avatar
  • 1,312
100 votes
13 answers
142k views

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 ...
Taha Jahangir's user avatar
98 votes
3 answers
133k views

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's user avatar
  • 3,810
90 votes
18 answers
118k views

Ansible stuck on gathering facts

I'm having some odd issues with my ansible box(vagrant). Everything worked yesterday and my playbook worked fine. Today, ansible hangs on "gathering facts"? Here is the verbose output: <5.xxx....
Bj Blazkowicz's user avatar
79 votes
6 answers
59k views

How to unify package installation tasks in ansible?

I am starting with ansible and will use it, among others, to install packages on several Linux distros. I see in the docs that the yum and apt commands are separated - what would be the easiest way ...
WoJ's user avatar
  • 3,617
65 votes
6 answers
115k views

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. ...
mjallday's user avatar
  • 922
63 votes
8 answers
101k views

Deploying a folder of template files using ansible

Is there an easy way to deploy a folder full of template .j2 folder to a linux box, using the same name as the template, but without the .j2 extension, rather than using the template module for each ...
Trololololol's user avatar
57 votes
4 answers
82k views

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....
Slava Fomin II's user avatar
57 votes
1 answer
128k views

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 ...
hryamzik's user avatar
  • 827
56 votes
2 answers
141k views

Convert value of an Ansible variable from lower case to upper case

I am working on a playbook to join linux systems to Active Directory. I can't seem to find a way to convert the value of ansible_hostname to uppercase. One of the commands I need to run requires the ...
grahamjgreen's user avatar
51 votes
3 answers
80k views

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 ...
Slava Fomin II's user avatar
48 votes
3 answers
99k views

Is there a way to check that a dictionary key is not defined in ansible task?

So in my code I have a task: - name: cool task shell: 'touch iamnotcool.txt' when: me.cool is not defined and my vars looks like: --- me: stumped: yes So when I run the task it comes back with ...
Luis F Hernandez's user avatar
46 votes
4 answers
31k views

Ansible security best practices

I am going to introduce Ansible into my data center, and I'm looking for some security best practice on where to locate the control machine and how to manage the SSH keys. Question 1: the control ...
Mat's user avatar
  • 1,893
45 votes
6 answers
138k views

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 ...
Craig Ringer's user avatar
  • 11.2k
44 votes
2 answers
53k views

How do I enable additional debugging output from Ansible and Vagrant?

I am investigating Ansible for server and application provisioning. My application is currently provisioned with shell scripts in Vagrant. Rather than rewriting my scripts, I took a sample and ...
Brian Lyttle's user avatar
  • 1,757
42 votes
3 answers
175k views

Running Ansible task as a specific user

I am trying to run a specific Ansible task as a different user than the one who is running the playbook. My .yml file looks like this: --- - hosts: staging_servers tasks: - name: check ...
errata's user avatar
  • 553
40 votes
3 answers
79k views

How to run multiple playbooks in order with Ansible?

I'm working on several Ansible playbooks to spin up a new server instance. There are approximately 15 different playbooks I need to run in a specific order to successfully spin up a server. My ...
nulltek's user avatar
  • 1,281
38 votes
6 answers
193k views

Install rpm package using Ansible

How do I install .rpm package on remote machine using Ansible? The obvious solution is to use command module, but that is a bit silly. Also I would like to avoid setting up a yum repository just for ...
NefariousOctopus's user avatar
37 votes
8 answers
128k views

Ansible: Conditionally define variables in vars file if a certain condition is met

Depending on the value(True/False) of a variable defined into the group_vars I am trying to define some variables in a vars file. Their value depends on the group var's value. My current var file ...
pandoJohn's user avatar
  • 425
35 votes
9 answers
107k views

How can I stop ansible from writing passwords to the logfiles?

I am setting up a MySQL server and want Ansible to set the mysql-root password during installation. With the help of the internet I came up with this solution: - name: Set MySQL root password before ...
claus's user avatar
  • 571
33 votes
7 answers
236k views

ansible print debug msg variable

I try to print the previously registered mosh_version variable using the ansible debug msg command like this: - name: Print mosh version debug: msg="Mosh Version: {{ mosh_version.stdout }}" It ...
Zulakis's user avatar
  • 4,213
31 votes
7 answers
29k views

How to handle SSH port changes with Ansible?

I'm trying to use Ansible for automating the setup process of new server instances. One of the setup tasks changes the default SSH port, therefore requiring me to update the hosts list. Is it ...
Miko's user avatar
  • 1,759
30 votes
10 answers
108k views

How to fetch multiple files from remote machine to local with Ansible

I would like to copy files from remote directory to local directory with Ansible but fetch module allows me to copy only one file. I have many servers from which I need files (same directory each ...
maayke's user avatar
  • 741
29 votes
6 answers
85k views

Ansible: How to run one Task Host by Host?

On the play-level, we have serial: 1 to allow us to run the whole play one host at a time. But I haven't found a simple way to do this on a single task. This is especially relevant, if the task in ...
Elrond's user avatar
  • 586
27 votes
11 answers
77k views

SSH aborts with Too many authentication failures

I'm attempting to run this simple provisioning script but I'm encountering errors when running vagrant up and then vagrant provision commands. I read that I needed to create a /etc/ansible/hosts file ...
Ashley's user avatar
  • 528
27 votes
1 answer
68k views

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 ...
030's user avatar
  • 5,971
27 votes
4 answers
70k views

Ansible: Is it possible to "cat file" and export it's output to screen while playing a playbook and not as debug?

I wrote a playbook which installs and configures Google Authenticator per user. I want the last step of the playbook to cat the google_authenticator configuration file. Using the "debug" module I am ...
Itai Ganot's user avatar
  • 10.7k
25 votes
6 answers
24k views

Running apt-get autoremove with ansible

I maintain a flock of EC2 servers with ansible. The servers are regularly updates and upgraded using the apt module. When I manually tried to upgrade a server, I received the following message: $ ...
Adam Matan's user avatar
  • 13.4k
25 votes
4 answers
46k views

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's user avatar
  • 1,177
24 votes
3 answers
21k views

Configuration management: push versus pull based topology

The more established configuration management (CM) systems like Puppet and Chef use a pull-based approach: clients poll a centralized master periodically for updates. Some of them offer a masterless ...
Willem's user avatar
  • 2,872
23 votes
2 answers
6k views

Will Ansible prevent the execution of 'rm -rf /' in a shell script

This is based upon this hoax question here. The problem described is having a bash script which contains something to the effect of: rm -rf {pattern1}/{pattern2} ...which if both patterns include ...
aroth's user avatar
  • 393
22 votes
7 answers
60k views

How to generate host SSH keys via ansible?

I'm trying to re-generate ssh host keys on a handful of remote servers via ansible (and ssh-keygen), but the files don't seem to be showing up. The playbook runs OK, but the files on the remote are ...
Server Fault's user avatar
  • 3,734
22 votes
4 answers
27k views

Iptables management with ansible in huge environment

What is the best way to manage iptables from one point and have the ability to edit something on local server. We need to add some rules centralized on all servers, but we have specific servers with ...
Navern's user avatar
  • 1,619
21 votes
3 answers
57k views

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 ...
s g 's user avatar
  • 621
21 votes
1 answer
17k views

How can I prepend to PATH while running Ansible's pip module?

I'm attempting to install psycopg2 into a Python virtualenv with Ansible's pip module, but I need to prepend an entry to PATH for it to build correctly (it needs to know the path to the directory ...
Collin Allen's user avatar
20 votes
3 answers
2k views

Managing cluster of linux computers behind firewalls

My company's product is essentially a Linux box (Ubuntu) sitting in somebody else's network running our software. Up to now we had less than 25 boxes in the wild and used TeamViewer to manage them. ...
hakura's user avatar
  • 303
20 votes
5 answers
46k views

How to destroy/delete/unset a variable value in Ansible?

Is there a way to destroy the variable in Ansible? Actually, I have a {{version}} variable being used in my all roles for respective packages. When I run multiple roles, the version value of one role ...
MMA's user avatar
  • 385
20 votes
4 answers
89k views

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. ...
Francesco Abeni's user avatar
20 votes
4 answers
37k views

How to make Ansible use password if key was rejected?

My new server instances are configured to login on root via ssh with password. I want my Ansible playbook to reconfigure it to use keys instead and disable root login with password on first run, so I ...
petr0's user avatar
  • 323
19 votes
3 answers
15k views

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={{...
Zulakis's user avatar
  • 4,213
19 votes
6 answers
13k views

Validate nginx.conf during ansible deploy

I have a single Ansible-provisioned server running a number of sites. My Ansible tasks look roughly like: - name: site nginx config template: src="nginx-site.conf.j2" dest=/etc/nginx/conf.d/{{item....
Erin Call's user avatar
  • 301
19 votes
3 answers
34k views

ansible blockinfile disable marker

I'm new to ansible, however I was able to successfully use the blockinfile function. However I can't figure out how to prevent markers from being inserted. I read the documentation but it didn't ...
Nik's user avatar
  • 197
18 votes
8 answers
78k views

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 ...
Kevin's user avatar
  • 837
18 votes
7 answers
39k views

Ansible: Can I use vars_files when some files do not exist

That's the part: vars_files: - vars/vars.default.yml - vars/vars.yml If a file vars/vars.yml does not exist - here is an error. ERROR: file could not read: /.../vars/vars.yml How can I load ...
Sergey's user avatar
  • 714
18 votes
1 answer
72k views

Loop over Ansible variable array in Jinja2 template

when Ansible gathers facts about hosts, it for example gets all the mounts of the host: "ansible_mounts": [ { "block_available": 7800291, "block_size": ...
ThatGuyOnTheNet's user avatar
18 votes
1 answer
9k views

The value True (type bool) in a string field was converted to u'True' (type string)

I'm trying to follow parameters/examples, yet running into following WARNING message while executing Ansible'playbook: TASK [apt (pre)] ****************************************************************...
alexus's user avatar
  • 13.2k
17 votes
3 answers
59k views

Creating a symlink with ansible and a list of variables

Brand new to ansible - I'm trying to symlink a bunch of files in a src directory to a destination.. Currently: file: src: /drupal/drush/{{ item.path }}.aliases.drushrc.php dest: /home/...
williamsowen's user avatar
  • 1,167

1
2 3 4 5
36