问题描述
我正在尝试将我们过去在本地运行的 Ansible Playbook 移至 Ansible Tower,但遇到了问题。
我们使用以下任务将配置文件复制到远程服务器:
- name: copy Config File
copy:
src: "files/propertyOverride.config"
dest: /opt/project/propertyOverride.config
owner: myuser
group: myuser
mode: '755'
这在本地运行时很好用,因为 Ansible 能够在当前目录中找到文件。
但是,当我将它移到 Ansible Tower 并尝试运行它时,看起来工作并不是从存放剧本的 git 存储库中提取该文件。我使用 git 作为项目的 SCM。
有没有办法从包含此 Ansible 项目的 git 存储库中引用文件?
解决方法
在这里回答我自己的问题。
看起来 Ansible 会自动从 git 中提取文件,但由于某种原因它不能使用绝对路径。当我把它改成这样:
// Start by saying your whole function is an async one
router.post('/api/v1/test',async (req,res) => {
... // (Your code comes here)
// A better way to do the loop
//for(const record of request){
// Object deconstruction is awesome
for(const { name,tech } of request){
try{
const rec = new testing({ name,tech })
// Here,now all the function waits for this next line
const a1 = await rec.save()
var data = new Record_response(name,tech,true)
client_response.partners.push(data)
}catch(err){
var data = new Record_response(name,false)
client_response.partners.push(data)
}
}
// So the client_response has finally something!
res.json(client_response)
});
它按预期工作。