LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-26-2018, 11:20 AM   #1
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Rep: Reputation: 2
ansiible: register when grep etc


Code:
- name: Httpd running ?
  shell: ps axo args |  grep httpd | grep -v grep 
  register: apache
  failed_when: false
  ignore_errors: yes <---- if this removed I get red error on non httpd servers

- name: Copy script
  get_url:
    url: "http://anotherscript.sh
    dest: /tmp/anotherscript.sh
    mode: 0755
    owner: root
    group: root
    force: yes
  when: apache.rc == 0
What I want is
Code:
when apache.rc == 0
   do  url; dest; mode; owner etc
   done
when apache.rc != 0 
    next
If I put " ignore_errors: yes " then it ignore apache.rc and do every thing(url, dest, mod etc) on a given server regardless it has httpd running or not.
If I remove " ignore_errors: yes " then it starts bringing red font errors on all the servers where httpd is not running.

Please help.

Last edited by PoleStar; 03-26-2018 at 11:22 AM.
 
Old 03-26-2018, 03:04 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You have to implement a branch of some sort following the ps command, do you know how to do it in ansiible?

Btw, a way to avoid grep -v grep
Code:
ps axo args | grep [h]ttpd
ignore_errors may ignores the exit return status from ps | grep command, I don't know

Last edited by keefaz; 03-26-2018 at 03:06 PM.
 
1 members found this post helpful.
  


Reply



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
from ps -ef | grep java how can I grep out Xms & Xmx value hjo99729 Linux - Newbie 3 10-26-2017 07:39 PM
Find & grep - how to return pathes, not grep phrases ? postcd Linux - General 2 11-25-2014 12:43 PM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
looking for Open-Source Asset Register Software, IT Equipment and Register Database boninebm Linux - Software 1 09-13-2011 04:56 AM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM

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

All times are GMT -5. The time now is 01:09 PM.

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