See below.
On Thursday, August 31, 2023 at 8:59:57 AM UTC-6 Will McDonald wrote:
This isn't really an Ansible problem per se unless it's *only* ansible in a
subshell that doesn't run from cron? Have you tested basic cron
functionality using something simple like this (or something even more
basic):
#!/bin/sh
z4=`date +%Y%m%d%H%M`
touch /tmp/${z4}
And then check to see if that file is created every 30 minutes *does* work?
Yes, it does. I know the script is running, because it is much elaborate
than this, creating files, logging, etc.
It's run is annotated in /var/log/cron. If there was an obvious error, like
no execute permission, I'd see something in a CMDOUT () message.
No errors.
I look at the /var/log/ansible.log, and I see the output I'd like to have,
in the ansible.log. They are just not being returned
to the script. It's as if it's a "term" sort of problem. So, in the
ansible.log, I see something like:
2023-08-29 17:38:18,067 p=84629 u=root n=ansible | mainmachine | CHANGED |
rc=0 >>
10.10.11.0##255.255.255.0
101.133.145.94##255.255.255.255
.
.
.
and mayhaps a hundred or so more entries.
First questions that spring to mind are:
- is there anything in the cron log, syslog or journal for the crond
service?
yes. /var/log/cron records it run. ansible.log shows that ansible is
called and generates the desired data. It's not being echoed to the stdout
of the ansible process, it appears.
- is anything else running successfully out of /etc/cron.d / cron.daily
etc?
Yep. All else seems well with the cron.d stuff.
- is crond enabled in whatever init system you're using? (You haven't
stated which distro?)
I'm running this cron on a AlmaLinux release 8.8 (Sapphire Caracal) OS.
On Thu, 31 Aug 2023 at 15:24, Steve Murphy <[email protected]> wrote:
As the subject line says, I can't get this script to run correctly from
cron.
My cron entry (in a file in /etc/cron.d):
======================================
# Run the 30-minly job
SHELL=/bin/bash
PATH=/sbin:/bin/:/usr/sbin:/usr/bin:/root
MAILTO=ROOT
*/30 * * * * root /root/getlist
======================================
/root/getlist perms a+r, a+x, u+w:
=====================================
#!/bin/bash
z4=`ansible mainmachine -m shell -a "psql -t -Upiquah -c
\"subnet.ipaddress || '##' || subnet.netmask from subnet order by
subnet.ipaddress asc;\"" 2>&1 | grep '^ [0-9]'`
echo $z4
=====================================
from which, if you run this "by hand", you'll get some output that looks
like this:
19.20.21.22##255.255.255.255 23.24.25.26##255.255.255.255
130.140.150.160##255.255.255.254
... and so forth.
BUT, if executed from cron, $z4 will be empty.
What do I need to do to in the cron.d file to make this work well?
--
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/33ab4c47-f91e-4587-a5f2-08341ecf4fa5n%40googlegroups.com.