以下语法可以正常工作。
---
- hosts: all
tasks:
- name: run this command and ignore the result
shell: echo "The server is UP since " `uptime`
但是,当我将外壳模块更改为命令模块时,我期望它仍然可以正常工作。
command: echo "The server is UP since " `uptime`
但是它不会使用命令模块显示正常运行时间值。
我不能使用相同的语法来同时使用外壳程序和命令模块吗?
答案 0 :(得分:1)
我不能使用相同的语法来同时使用外壳程序和命令模块吗?
是的,当然,只需手动完成const getSuffix = (num) => {
const suffixes = {
'1': 'st',
'21': 'st',
'31': 'st',
'2': 'nd',
'22': 'nd',
'3': 'rd',
'23': 'rd'
};
return suffixes[num] || 'th';
};
function convertDateToString(date) {
let monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
let dayNames = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
let dayIndex = date.getDate();
let monthIndex = date.getMonth();
let year = date.getFullYear();
return dayNames[dayIndex] + ', ' + monthNames[monthIndex] + ' ' + dayIndex + getSuffix(dayIndex) + ' ' + year;
}
let date = new Date()
console.log(convertDateToString(date));
// wanted format: Thursday, May 2nd 2019
要做的工作并将字符串包装在shell:
sh -c