Shell

使用 ansible.builtin.shell 時的 ansible 問題

  • March 5, 2022
$ ansible all -m ansible.builtin.shell  -a 'echo $TERM'
ERROR! this task 'ansible.builtin.shell' has extra params, which is only
allowed in the following modules: import_role, win_command,
include_vars, include_tasks, raw, win_shell, command, add_host, 
meta, include_role, shell, import_tasks, group_by, set_fact, script, include

誰能幫我找出問題所在

這是帶-vvv標籤的

$ ansible -vvv centos -m ansible.builtin.shell  -a 'echo $TERM'
ansible 2.9.6
 config file = /etc/ansible/ansible.cfg
 configured module search path = ['/home/chandru/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
 ansible python module location = /usr/lib/python3/dist-packages/ansible
 executable location = /usr/bin/ansible
 python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
ERROR! this task 'ansible.builtin.shell' has extra params, which is only allowed in the following modules: group_by, include_tasks, set_fact, raw, add_host, win_shell, win_command, include_vars, meta, import_role, command, script, include, shell, import_tasks, include_role

這是由於 Ansible 中的一個錯誤,該錯誤是作為向 FQCN 過渡的一部分引入的:https ://github.com/ansible/ansible/pull/71824

作為一種解決方法,您可以簡單地替換ansible.builtin.shell為老式shell名稱。

你可以試試:

$ ansible all -m shell  -a 'echo $TERM'

我的環境:

root@ubuntu:~/ansiblelearn# ansible --version
ansible 2.9.6
 config file = /etc/ansible/ansible.cfg
 configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
 ansible python module location = /usr/lib/python3/dist-packages/ansible
 executable location = /usr/bin/ansible
 python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]

引用自:https://unix.stackexchange.com/questions/633010