LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-28-2017, 02:58 AM   #1
hruday
Member
 
Registered: Jun 2015
Posts: 88

Rep: Reputation: Disabled
Ansible doesn't abort even after a command fails executing


I am using ansible to execute commands by picking up each one from a text file (say sample.txt)

sample.txt has following commands

echo "hello world"
df -h
free -m
mkdir /tmp/`hostname`_bkp
touch /tmp/`hostname`_bkp/file{1..5}
mvn -version
echo "directory and files craeted"
echo "Bye.!"


Now if start running playbook it executes but never aborts when command fails, it just shows error and executes next command.

I want to abort the ansible when command fails like in my case I dont have maven installed so "mvn -version" should fail and ansible should abort.

I've written my playbook as follows

---

- hosts: localhost

tasks:

- name: this command prints FAILED when it fails
command: cat /root/ansi-pb/sample.txt
register: my_items
failed_when: "'command not found' in my_items.stderr"

- name: installation
shell: "{{ item }}"
with_items: "{{ my_items.stdout_lines }}"
# failed_when: "'command not found' in my_items.stderr"

# fail: msg="command failed"
# when: "'command not found' in my_items.stderr"

# - name: fail the play if the previous command did not succeed
# fail: msg="the command failed"
# when: "'command not found' in my_items.stderr"

# - fail:
# msg: "The system may not be provisioned according to the CMDB status."
# when: "'command not found' in my_items.stderr"


and also I want ansible to start execution from where it failed like if it fails at "mvn -version" then next time when I run playbook it should start from that command instead of starting from first command in the text file.

How can i achieve this?
 
Old 03-01-2017, 09:52 AM   #2
mkempster22
LQ Newbie
 
Registered: Feb 2017
Location: England
Distribution: RedHat/Ubuntu
Posts: 8

Rep: Reputation: Disabled
Have you tried the option stated here:
http://docs.ansible.com/ansible/play..._handling.html

Under 'Aborting the Play'

Could be too extreme for what you're looking for
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Abort command issued mihirict Linux - Hardware 2 04-08-2019 05:32 AM
[SOLVED] QLA2XXX driver on Debian, Abort command issued marcink325 Linux - Hardware 2 08-26-2011 02:06 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM
how to abort command sumeet inani Linux - Newbie 7 04-26-2009 08:39 AM
executing matlab fails provkitir Linux - Software 2 07-01-2005 03:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration