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
32
votes
5 answers

ansible returns with "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6))

I am running myserver in ubuntu: + sudo cat /etc/os-release NAME="Ubuntu" VERSION="16.04.6 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.6…
Learner
  • 1,686
  • 4
  • 19
  • 38
32
votes
6 answers

How can I check if a string exists in a file?

Is it possible to check if a string exists in a file using Ansible? I want to check is a user has access to a server. This can be done on the server using cat /etc/passwd | grep username, but I want Ansible to stop if the user is not there. I have…
Frostie_the_snowman
  • 629
  • 3
  • 9
  • 17
32
votes
1 answer

How to disable gathering facts for subplays not included within given tag

Several of my playbooks have sub-plays structure like this: - hosts: sites user: root tags: - configuration tasks: (...) - hosts: sites user: root tags: - db tasks: (...) - hosts: sites user: "{{ site_vars.user }}" …
Michal
  • 6,411
  • 6
  • 32
  • 45
31
votes
1 answer

Conflicting action statement in ansible

I am getting the following error : Conflicting action statement in ansible. I tried to understand, my code seems to be correct. I declared the name correctly though it gives an error in the task name. Playbook: --- - hosts: webhost sudo: yes …
robert williams
  • 747
  • 2
  • 11
  • 18
30
votes
2 answers

Ansible 2.1.0 using become/become_user fails to set permissions on temp file

I have an ansible 2.1.0 on my server, where I do deployment via vagrant and on PC too. The role "deploy" have : - name: upload code become: true become_user: www-data git: repo=git@bitbucket.org:****.git dest=/var/www/main …
DeamonMV
  • 722
  • 1
  • 10
  • 19
29
votes
5 answers

Formatting stdout in a debug task of Ansible

Assuming the below tasks: - shell: "some_script.sh" register: "some_script_result" - debug: msg: "Output: {{ some_script_result.stdout_lines }} I receive the below output: "msg": "Output: [u'some_value',u'some_value2,u'some_value3]" How do…
Kimmel
  • 485
  • 1
  • 4
  • 12
29
votes
3 answers

ansible if else construct

Heres my if else Ansible logic .. - name: Check certs exist stat: path=/etc/letsencrypt/live/{{ rootDomain }}/fullchain.pem register: st - include: ./_common/check-certs-renewable.yaml when: st.stat.exists - include:…
danday74
  • 52,471
  • 49
  • 232
  • 283
29
votes
5 answers

How to add spaces at beginning of block in Ansible's blockinfile?

I found this blockinfile issue, where a user suggested adding a number after the "|" in the "block: |" line, but gives a syntax error. Basically, I want to use blockinfile module to add a block of lines in a file, but I want the block to be indented…
Chris F
  • 14,337
  • 30
  • 94
  • 192
28
votes
1 answer

Execute curl -X with ansible playbook

I want to execute the next command using ansible playbook: curl -X POST -d@mesos-consul.json -H "Content-Type: application/json" http://marathon.service.consul:8080/v2/apps How can I run it? If I run: - name: post to consul uri: url:…
Asier Gomez
  • 6,034
  • 18
  • 52
  • 105
26
votes
1 answer

How to use ansible 'expect' module for multiple different responses?

Here I am trying to test my bash script where it is prompting four times. #!/bin/bash date >/opt/prompt.txt read -p "enter one: " one echo $one echo $one >>/opt/prompt.txt read -p "enter two: " two echo $two echo $two >>/opt/prompt.txt read -p…
Pankaj Jackson
  • 3,521
  • 3
  • 15
  • 19
26
votes
2 answers

Ansible: ansible_user in inventory vs remote_user in playbook

I am trying to run an Ansible playbook against a server using an account other than the one I am logged on the control machine. I tried to specify an ansible_user in the inventory file according to the documentation on…
techraf
  • 64,883
  • 27
  • 193
  • 198
25
votes
6 answers

How can I get a list of hosts from an Ansible inventory file?

Is there a way to use the Ansible Python API to get a list of hosts from a given inventory file / group combination? For example, our inventory files are split up by service…
MrDuk
  • 16,578
  • 18
  • 74
  • 133
24
votes
5 answers

How to kill a running process using ansible?

I have an ansible playbook to kill running processes and works great most of the time!, however, from time to time we find processes that just can't be killed so, "wait_for" gets to the timeout, throws an error and it stops the process. The current…
Julio Fernandez
  • 255
  • 1
  • 2
  • 5
24
votes
1 answer

Is it possible to have Ansible retry on connection failure?

I am facing this annoying bug: Ansible hosts are randomly unreachable #18188 . Is there a way to tell Ansible that if SSH connection fails, to try it once more? Or 2 times more? According this post New SSH Retry In Ansible 2.0? there is "retries"…
Petr
  • 13,747
  • 20
  • 89
  • 144
23
votes
2 answers

iteration using with_items and register

Looking for help with a problem I've been struggling with for a few hours. I want to iterate over a list, run a command, register the output for each command and then iterate with debug over each unique registers {{ someregister }}.stdout For…
cachonfinga
  • 860
  • 2
  • 8
  • 14