这个错误通常是在Ansible Playbooks中使用了无效的目录路径或者在shell模块的命令中给出了多个目录参数。
例如,在以下命令中:
- name: Move files
shell: cd /path/to/source /path/to/destination && cp file* {{ dest }}
会导致“ansible: cd: too many arguments”错误。要解决这个问题,请确保在shell模块的命令中只给出一个目录路径参数,并将所有参数用分号或者换行符隔开。
- name: Move files
shell: |
cd /path/to/source
cd /path/to/destination
cp file* {{ dest }}
或者使用“&&”分隔两个命令,如下所示:
- name: Move files
shell: cd /path/to/source && cp file* /path/to/destination && cp file* {{ dest }}