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

reading json like variable in ansible

I'm new to ansible and I'm having a problem reading a value from json file in ansible role. my variable has a value like the following: { "queue": { "first": { "car": "bmw", "year": "1990", "model": "x3", "color":…
tkyass
  • 2,968
  • 8
  • 38
  • 57
21
votes
3 answers

how to read json file using ansible

I have a json file in the same directory where my ansible script is. Following is the content of json file: { "resources":[ {"name":"package1", "downloadURL":"path-to-file1" }, {"name":"package2", "downloadURL":…
Shasha99
  • 1,746
  • 2
  • 16
  • 30
19
votes
2 answers

Using chown command in ansible?

I have a command in ubuntu as sudo chown $(id -u):$(id -g) $HOME/.kube/config I want to convert into ansible script. I have tried below - name: Changing ownership command: chown $(id -u):$(id -g) $HOME/.kube/config become: true…
TechChain
  • 8,404
  • 29
  • 103
  • 228
19
votes
1 answer

Ansible template adds 'u' to array in template

I have the following vars inside of my ansible playbook I got the following structure domains: - { main: 'local1.com', sans: ['test.local1.com', 'test2.local.com'] } - { main: 'local3.com' } - { main: 'local4.com' } And have the following…
Steve
  • 1,213
  • 5
  • 16
  • 29
18
votes
5 answers

Can the templates module handle multiple templates / directories?

I believe the Ansible copy module can take a whole bunch of "files" and copy them in one hit. This I believe can be achieved by copying a directory recursively. Can the Ansible template module take a whole bunch of "templates" and deploy them in one…
danday74
  • 52,471
  • 49
  • 232
  • 283
18
votes
3 answers

Ansible: How to add variables to "command" or "shell"

Is it possible to use variables on command or shell modules? I have the following code, and I would like to use variable file to provide some configurations: I would like to read the Hadoop version from my variables file. On other modules of ansible…
Asier Gomez
  • 6,034
  • 18
  • 52
  • 105
17
votes
2 answers

How to add multiple inventory files in command line while executing a playbook

I am having a playbook with two different plays Sample.yml - name : Play1 hosts: Host1 tasks: ... - name: Play2 hosts: Host2 tasks: ... I need to run this playbook with two different hosts(Host1 and…
prasanna kumar
  • 257
  • 3
  • 4
  • 17
17
votes
1 answer

How to run only one role of an Ansible playbook?

I have a site.yml which imports several playbooks. - import_playbook: webservers.yml - .... Every playbook "calls" several roles: - name: apply the webserver configuration hosts: webservers roles: - javajdk - tomcat - apache How can…
Michael Hoeller
  • 22,018
  • 10
  • 39
  • 66
17
votes
1 answer

How to convert a dictionary of dictionaries into a list of dictionaries in a Ansible vars file?

Within an Ansible vars file, I want to convert a dict of dicts into a list of dicts that I can pass to an external role from Ansible Galaxy. Input: postgres_users: dc1: name: user_dc1 password: pass_dc1 dc2: name: user_dc2 …
Jeff Widman
  • 22,014
  • 12
  • 72
  • 88
16
votes
1 answer

Ansible ad-hoc command with direct host specified - no hosts matched

I am running a 16.04 Ubuntu desktop machine using VirtualBox. This VM has Ansible 2.4.0 installed. I am trying to run an ad-hoc ansible command just to prove it works (I am doing an online course). To simulate a small server farm, I use lxc (linux…
TomTom
  • 318
  • 1
  • 3
  • 15
16
votes
2 answers

How to use omit with Ansible and avoid any errors?

I tried to use omit with an expression like this: id: "{{ openstack_networks.id | default(omit) }}" But it seems that it keeps failing with an exception when openstack_networks variable is not defined. What is the correct way to write this jinja2…
sorin
  • 161,544
  • 178
  • 535
  • 806
15
votes
2 answers

Correct way to create dynamic lists in Ansible

I'm looking for advice. I have the following code that creates a list dynamically that I can then later use in a template. This is a copy of the test code I put together - for the actual role I just added the admins|regex_replace variable into the…
cachonfinga
  • 860
  • 2
  • 8
  • 14
15
votes
5 answers

Jinja2 filter list using string contains test

I'm trying to filter a list in ansible in Jinja2 when the elements contain a string, but the Jinja documentation doesn't seem clear enough for me to figure it out. This is what I have so far: - name: run script command: /usr/tmp/run_script.py …
CorayThan
  • 17,174
  • 28
  • 113
  • 161
14
votes
3 answers

Running a playbook on multiple host groups one at a time

I want to run a playbook containing some roles on multiple host groups I create dynamically with the group_by module. I'm able to do it like the example below (ping replacing my actual role). I was wondering if there is a way to run each group…
Shay Rybak
  • 1,193
  • 1
  • 9
  • 9
14
votes
3 answers

Ansible delegate_to how to set user that is used to connect to target?

I have an Ansible (2.1.1.) inventory: build_machine ansible_host=localhost ansible_connection=local staging_machine ansible_host=my.staging.host ansible_user=stager I'm using SSH without ControlMaster. I have a playbook that has a synchronize…
RokL
  • 2,663
  • 3
  • 22
  • 26