Questions tagged [ansible-2.x]

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems

Ansible 2.x is a new backwards-incompatible version that involved a rewrite of the core, and a new API.

Ansible 2.x features new commands like ansible-vault, allowing you to store encrypted information in playbooks and have them decrypted on the fly. It also includes new concepts like Task Blocks, Dynamic Includes, Execution Strategy Plugins, and a suite of new "batteries included" modules. Most importantly, new releases are named after Led Zepplin songs, rather than Van Halen.

https://raw.githubusercontent.com/ansible/ansible/stable-2.0/CHANGELOG.md

Related Tags

1908 questions
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
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
74
votes
6 answers

Accessing inventory host variable in Ansible playbook

In Ansible 2.1, I have a role being called by a playbook that needs access to a host file variable. Any thoughts on how to access it? I am trying to access the ansible_ssh_host in the test1 section of the following inventory host…
ali haider
  • 19,175
  • 17
  • 80
  • 149
74
votes
4 answers

Difference between become and become_user in Ansible

Recently I started digging into Ansible and writing my own playbooks. However, I have a troubles with understanding difference between become and become_user. As I understand it become_user is something similar to su , and become means…
Andrii Rusanov
  • 4,405
  • 2
  • 34
  • 54
74
votes
7 answers

Unexpected Exception: name 'basestring' is not defined when invoking ansible2

I'm trying to execute ansible2 commands... When I do: ansible-playbook -vvv -i my/inventory my/playbook.yml I get: Unexpected Exception: name 'basestring' is not defined the full traceback was: Traceback (most recent call last): File…
code_monk
  • 9,451
  • 2
  • 42
  • 41
72
votes
12 answers

Ansible: copy a directory content to another directory

I am trying to copy the content of dist directory to nginx directory. - name: copy html file copy: src=/home/vagrant/dist/ dest=/usr/share/nginx/html/ But when I execute the playbook it throws an error: TASK [NGINX : copy html file]…
Asier Gomez
  • 6,034
  • 18
  • 52
  • 105
71
votes
1 answer

How to create a relative symlink in Ansible?

In my playbook, I need to create a symbolic link for a repo. With command (shell) it may work like this: ########## Create symbolic link - name: Create symbolic link shell : ln -s "{{SOURCE_FOLDER}}" SYMLINK args : chdir :…
firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
56
votes
4 answers

How can I show progress for a long-running Ansible task?

I have a some Ansible tasks that perform unfortunately long operations - things like running an synchronization operation with an S3 folder. It's not always clear if they're progressing, or just stuck (or the ssh connection has died), so it would…
Xiong Chiamiov
  • 13,076
  • 9
  • 63
  • 101
54
votes
2 answers

Ansible remote_user vs ansible_user

The question is simple: what is the difference between ansible_user (former ansible_ssh_user) and remote_user in Ansible, besides that the first one is set if configuration file and the latter one is set in plays / roles? How do they relate to -u /…
madhead
  • 31,729
  • 16
  • 153
  • 201
50
votes
5 answers

How do I pass username and password while using Ansible Git module?

While doing clone, push or pull of a private git repository hosted internally (e.g. on a GitLab instance) with Ansible's Git module, how do I specify username and password to authenticate with the Git server? I don't see any way to do this in the…
karthik v
  • 1,104
  • 1
  • 14
  • 22
49
votes
5 answers

Using True False with Ansible When Clause

I'm running into the silliest issue. I cannot figure out how to test for boolean in an Ansible 2.2 task file. In vars/main.yml, I have: destroy: false In the playbook, I have: roles: - {'role': 'vmdeploy','destroy': true} In the task file,…
Simply Seth
  • 3,246
  • 17
  • 51
  • 77
44
votes
6 answers

How to loop over this dictionary in Ansible?

Say I have this dictionary war_files: server1: - file1.war - file2.war server2: - file1.war - file2.war - file3.war and for now I just want to loop over each item (key), and then over each item in the key (value). I did this - name:…
Chris F
  • 14,337
  • 30
  • 94
  • 192
41
votes
13 answers

Ansible Timeout (12s) waiting for privilege escalation prompt

I'm having trouble running my Ansible playbook on AWS instance. Here is my version: $ ansible --version ansible 2.0.0.2 I created an inventory file as: [my_ec2_instance] default ansible_host=MY_EC2_ADDRESS ansible_user='ubuntu'…
vmenezes
  • 1,076
  • 2
  • 12
  • 21
34
votes
7 answers

Running Python script via ansible

I'm trying to run a python script from an ansible script. I would think this would be an easy thing to do, but I can't figure it out. I've got a project structure like this: playbook-folder roles stagecode files …
CorayThan
  • 17,174
  • 28
  • 113
  • 161
33
votes
5 answers

How to compare kernel (or other) version numbers in Ansible

For a role I'm developing I need to verify that the kernel version is greater than a particular version. I've found the ansible_kernel fact, but is there an easy way to compare this to other versions? I thought I might manually explode the version…
TobyG
  • 1,692
  • 3
  • 21
  • 36
1
2 3
99 100