Highlighted
Cadet
Cadet
  • 1,075 Views

How to use ansible ad hoc commands in shell scripts

Hello everybody,

I am on DO407 which does not cover that topic at all, so atm I am totally lost with that topic - could anybody please provide any ("official") resource how to do that really correctly?

Thank you so much

Cheers 

Martin

 

Labels (1)
0 Kudos
4 Replies
Highlighted
Flight Engineer Flight Engineer
Flight Engineer
  • 1,031 Views

Re: How to use ansible ad hoc commands in shell scripts

Hello,

think of it, like you write in on the cli.

Example:

#!/bin/bash

export ANSIBLE_LOG_PATH="$(mktemp --suffix=_ansible.log)"

echo "Starting the ansible ping ..."
ansible all -m ping >/dev/null 2>&1
ansible_exit=$?
if [ $ansible_exit -eq 0 ]
then
    echo "Finished ansible ping"
else
    echo "Something went wrong (Exit Code was ${ansible_exit})"
fi
echo Logfile available at $ANSIBLE_LOG_PATH
exit $ansible_exit

 

Best regards
Andreas

0 Kudos
Reply
Loading...
Highlighted
Cadet
Cadet
  • 1,013 Views

Re: How to use ansible ad hoc commands in shell scripts

Hi Andreas,

 

thank you for your answer.  Interesting approach with the logging part - but IS that really necessary? 

But to be honest, I would expect that you would not get full score with that script, though...

Question aims EX407, of course, but with the NDA stuff it is really, really hard to discuss issues duing an exam if you are on your own with the online learning plattform... and you get no help with the "expert chat" or from lering team via mail...

 

So...

Try to be abstract...

Assume the follwing:

If you run ansible on the command line, with all option needed (full path to inventory, remote_user, privilege escalation), and that command is idempotent for sure, and if you check all managed nodes you see that the command works as expected - if you put that line in a sript, of course with a shebang first, make that script exececutable - I guess you can be sure that it will work, of course, as on the command line, it will be correct, idempotent and so on - but you will not get full score during, too. And I do not understand why, and it drives me just crazy...

So question is: What is really needed when writing sripts with adhoc command. Any environemntal?

Still no idea...

 

Sorry, thank you

Regards

Martin

P.S.: Already passed EX407, all other parts almost 100%...

0 Kudos
Reply
Loading...
Highlighted
Flight Engineer Flight Engineer
Flight Engineer
  • 998 Views

Re: How to use ansible ad hoc commands in shell scripts

Hello,

it was just an example for illustration purpose. Of course the logging thing is not necessary.

Whatever goes wrong during the exam, I can not help!

Best regards
Andreas

 

0 Kudos
Reply
Loading...
Highlighted
Flight Engineer Flight Engineer
Flight Engineer
  • 895 Views

Re: How to use ansible ad hoc commands in shell scripts

Hi 

I think you can join Ansible essentials overview course .This is video class room course and also you can also check ansible doc. there is lots of training videos and documentation. 

https://www.redhat.com/en/services/training/do007-ansible-essentials-simplicity-automation-technical...

https://docs.ansible.com/

Thanks

 

 

 

 

 

ST
0 Kudos
Reply
Loading...
Join the discussion
You must log in to join this conversation.