Checking the return-code before continuing

31 views
Skip to first unread message

Herbie van Dalsen

unread,
Apr 4, 2016, 9:05:16 AM4/4/16
to Ansible Project
Hi there

I literally jut started with Ansible, and I can already see it is going to be a long road to get where I can use if to install jboss :)

I am therefore not ready for playbooks yet, and just like to execute the commands like this for now:

####################
# Define the user
####################
#
ansible gby-linux -a "useradd -d /home/davidl -m -s /bin/tcsh  davidl"
#
#Supply the userid with a passwd
#################################
ansible gby-linux -a "echo abc123 l passwd davidl --stdin"
#
# Expire the userid
#################################
ansible gby-linux -a "/usr/chage -d 0 davidl"
#
#################################
#gby-linux would be a group
#of servers in /etc/ansible/hosts
#################################

I would for now just like to build in a check on each of the steps to see if the previous 'rc' was zero before continuing, but I just cannot get any examples.

Lastly, what would be a good link to get the basics right before starting.

Thank You in Advance

Kind Regards

Herbie

Brian Coca

unread,
Apr 4, 2016, 12:12:57 PM4/4/16
to ansible...@googlegroups.com
running adhoc as you do here there is only the return code from ansible itself, which should reflect if the task failed or not.

In a playbook you can register a variable for each task and check against the |success filter on the next.



--
----------
Brian Coca

Johannes Kastl

unread,
Apr 6, 2016, 1:13:49 PM4/6/16
to ansible...@googlegroups.com
On 03.04.16 15:55 Herbie van Dalsen wrote:

> #Supply the userid with a passwd
> #################################
> ansible gby-linux -a "echo abc123 l passwd davidl --stdin"

Before you go down this road any longer, please consider using a
playbook with your passwords stored in ansible-vault. In this case
the password is visible in the .bash_history or similar, also in the
process list. Not safe...

Johannes

signature.asc
Reply all
Reply to author
Forward
0 new messages