Score:0

ansible-playbook: command not found when running bash with cron

cn flag

Running on ubuntu18, have a bash job to collect data from a router using ansible. Here is the bash script

#!/bin/bash
cd ~/datacollect
ansible-playbook -i /home/user/datacollect/hosts /home/user/datacollect/datacollect.yml

If I run the bash job from ubuntu console, there is no issue. Since we need to collect data every 5 minutes, I created a cron job for it.

* * * * *  /home/user/datacollect/call.sh

The data was not saved to the output file, at the beginning, I thought something stopped the cron job to run, then I found the information from /var/mail/user

Subject: Cron <user@host> /home/user/datacollect/call.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/user>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=user>
Message-Id: <20211008092301.EB6B8262437@host>
Date: Fri,  8 Oct 2021 20:23:01 +1100 (AEDT)

/home/user/datacollect/call.sh: line 3: ansible-playbook: command not found

It may be related to path environment setup as below, but I am not sure how to check and modify and not sure if it is the root cause. -bash: ansible-playbook: command not found

cn flag
In the cron job, I have to specify the path as below to make it work PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.