【问题标题】:ansible playbook / bash scriptansible 剧本/bash 脚本
【发布时间】:2022-11-18 20:55:24
【问题描述】:
你好/你好
首先抱歉我的英语很差,我是法国人,我用的是谷歌翻译。
我正在使用 ansible 剧本来运行 bash 脚本。在我的测试环境中它可以工作,但在我的生产环境中却不行,我不明白为什么。
这是一个允许扫描违规行为、检查服务状态并在最后生成报告的脚本。
在 ansible 中,任务完成但未生成报告,而当我直接从我的虚拟机(由 aws 托管)的终端运行脚本时,脚本工作并为我生成报告。
你能帮我吗 ?
- name: run the scan to generate deviation report
become: yes
command: sh /<path>
我尝试了几个命令,但我总是得到相同的结果。我尝试了 ansible 脚本模块并使用 bash -x 在调试模式下启动它
【问题讨论】:
标签:
automation
ansible
production-environment
【解决方案1】:
我测试如下
脚本:
root@swarm01:/myworkspace/ansible# cat hello.sh
#!/usr/bin/sh
touch abc
剧本。
root@swarm01:/myworkspace/ansible# cat test.yml
- name: simple script
hosts: localhost
tasks:
- name: simple script
command: sh hello.sh
root@swarm01:/myworkspace/ansible# ansible-playbook test.yml
PLAY [simple script] ***********************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************
ok: [localhost]
TASK [simple script] ***********************************************************************************************************************************
changed: [localhost]
PLAY RECAP *********************************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
它对我有用,我看到创建了一个 abc 文件。