I use this ansible cron to push the script to the host. I noticed that the cron task will run but the script will not run. But if I run the script from the CLI, it will run well. Please, I need help resolving this. What do I have to do at the "job" parameter to make it start the script? Even when the script run on the CLI, the docker compose command will not run? Is there a problem with the docker-compose up/down command?
ansible.builtin.cron:
name: daily apt upgrade
minute: "0"
hour: "3"
weekday: "6"
job: "sh /opt/apt_upgrades/update.sh | tee > /opt/apt_upgrades/log/upgrade.txt 2>&1"
state: present
Here is the bash script (/opt/apt_upgrades/update.sh
)
#!/bin/bash
cd /opt/docker-compose/; #does not run
docker-compose down; #does not run
sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove && sudo apt autoclean | tee > /opt/apt_upgrades/log/upgrade.txt 2>&1;
sleep 5;
echo "Current time: $(date +%T)";
cd /opt/docker-compose/; #does not run
docker-compose up --detach; #does not run
I have tried making changes to ansble
ansible.builtin.cron:
name: daily apt upgrade
minute: "0"
hour: "3"
weekday: "6"
job: "./root/.bashrc; /opt/apt_upgrades/update.sh | tee > /opt/apt_upgrades/log/upgrade.txt 2>&1"
state: present