Ansible使用ansible.builtin.shell本地执行脚本报多余参数错误如何解决?
Ansible shell任务报错解决方案
报错原因
你当前使用的Ansible版本低于2.10,不支持ansible.builtin.*格式的完全限定模块名称(FQCN)写法,旧版本仅能识别shell这类短模块名,因此会将合法的args参数误判为未知模块的多余参数,抛出对应报错。
解决方案
- 方案一(无需升级Ansible,直接修改任务配置即可):将模块名从
ansible.builtin.shell替换为旧版本兼容的短名称shell,修改后的配置如下:
- name: "Cherrytree - execute build.sh" shell: "./build.sh" args: chdir: /opt/Build/cherrytree
如果执行时提示脚本无执行权限,可新增前置授权任务:
- name: "Grant execute permission to build.sh" ansible.builtin.file: path: /opt/Build/cherrytree/build.sh mode: '0755'
- 方案二:将Ansible版本升级到2.10及以上,原生支持FQCN写法,无需修改现有任务配置即可正常运行。
内容的提问来源于stack exchange,提问作者just1han85
相关产品推荐
相关产品推荐

