
ansibleコマンドを使用したいのですが、dpkg -l | grep -i staff
エラーが発生します。
ansible all -m 'dpkj -l | grep -i stuff'
ERROR! this task 'dpkj' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars, include_tasks, include_role, import_tasks, import_role, add_host, group_by, set_fact, raw, meta
それからそれのスクリプトを作成しました。
- hosts: all
tasks:
- name: Ansible command
command: dpkg -l | grep -i staff
再びエラーが発生します。
FAILED! => {"changed": true, "cmd": ["dpkg", "-l", "|", "grep", "-i", "staff"], "delta": "0:00:00.010754", "end": "2019-06-26 18:15:10.373642", "msg": "non-zero return code", "rc": 1, "start": "2019-06-26 18:15:10.362888", "stderr": "dpkg-query: no packages found matching |\ndpkg-query: no packages found matching -i\ndpkg-query: no packages found matching stuff"
ansibleを使用してこのコマンドをどのように実行できますか?
答え1
簡単なコマンドでパイプを使用します。Ansible: 「シェル」と「コマンド」モジュールの違いこのモジュールのAnsibleドキュメントには次のものがありますcommand
。
コマンドはシェルを介して処理されないため、$ HOMEなどの変数、および
<
など>
の|
操作;
は&
何の影響もありません。これらの機能が必要な場合は、シェルモジュールを使用してください。
|
このタスクリストで「機能しない」記号を確認してください。