i am using ansible cron module
i am facing an issue when placing a job in ansible
ansible escapes special characters
my example job is:
(((( /usr/bin/php /var/www/file.php )))) > /var/log/cron.stderr 2>&1; if [ $? -gt 0 ]; then echo CronRun @ Error; fi
i am unable to deploy exit status $? to the remote machine crontab. it converts special chars $? to
What to do please help
Hi,
could you please paste your task and your ansible version as I’ve just tested with this task :
- name: Install cron
cron:
name: test issue
minute: 0
hour: 0
user: root
job: “(((( /usr/bin/php /var/www/file.php )))) > /var/log/cron.stderr 2>&1; if [ $? -gt 0 ]; then echo CronRun @ Error; fi”
cron_file: “test_cron”
and Ansible version 2.7.0 and I have this as output
cat test_cron
#Ansible: test issue
0 0 * * * root (((( /usr/bin/php /var/www/file.php )))) > /var/log/cron.stderr 2>&1; if [ $? -gt 0 ]; then echo CronRun @ Error; fi
Thanks
HI,
Thanks for your effor
i think my ansible version is previous its 2.0.0.2
Let me try and get back asap
I have tried with ansible version 2.7.1
Still same issue
i am constructing my command from nodejs backend
crontab_string += "(((( " + data.cron_details.job + " )))) > " + stderr + " 2>&1" ;
crontab_string += "; if [ $? -gt 0 ]" +
"; then echo CronRun @ Error >> " + log_file +
"; date >> " + log_file +
"; cat " + stderr + " >> " + log_file +
"; else echo CronRun @ Success >> " + log_file +
"; date >> " + log_file +
"; fi";
Thanks
fixed it by escaping if [ \$?\ -gt 0 ]
which results in if [ $? -gt 0]