Expectモジュールを使用して、タスクにansible_python_interpreterを追加します。 make_userを使用してコマンドを取得することはできません。

Expectモジュールを使用して、タスクにansible_python_interpreterを追加します。 make_userを使用してコマンドを取得することはできません。

私はCentOS7即時の会話が行われるべきインベントリクエストを作成していますが、これがexpectandibleモジュールに最適な候補だと思います。

- name: setup some command
  become: yes
  become_user: user1
  expect:
    command: some_command
    responses:
      'Do you want to continue? [yes/no]': 'y'

上記の作業ではpexpectインベントリにパッケージが必要で、利用可能なバージョン2.3 エラーが以下に表示されますが、予想されるバージョンは> = 3.3です。

fatal: [target1]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Insufficient version of pexpect installed (2.3), this module requires pexpect>=3.3. Error was 'module' object has no attribute '_run'"}

解決策としてインベントリモジュールをインストールし、タスクにpython3それpexpectansible_python_interpreter解決するように指定しました。今回はコマンドが見つかりませんbecome_user

- name: setup some command
  vars:
    ansible_python_interpreter: /usr/bin/python3
  become: yes
  become_user: user1
  expect:
    command: some_command
    responses:
      'Do you want to continue? [yes/no]': 'y'

以下は操作に関するエラーです。

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: pexpect.exceptions.ExceptionPexpect: The command was not found or was not executable: some_command.
fatal: [target1]: FAILED! => {"changed": false, "msg": "The command was not found or was not executable: some_command."}

不足していることをお勧めします

ベストアンサー1

Debianシステムでも同じ問題がありましたが、コマンドへのフルパスを使用して機能させることができました。whichたとえば、which some_commandリモートサーバーでを使用してコマンドのフルパスを取得できます。

フルパスを使用したAnsible Playbookの操作例

- name: setup some command
  become: yes
  become_user: user1
  expect:
    command: /usr/bin/some_command
    responses:
      'Do you want to continue? [yes/no]': 'y'

さらに調査した結果、これがAnsibleの一括ログインのためであることがわかりました。

とにかく、これはAnsibleがリアルタイムログインと同じファイルを取得しない一括ログインを実行するためです。これはシステム構成によって異なり、両方のログインタイプに対して同じPATHを設定することで変更できます。 源泉

ansible <host> -m shell -a "echo $PATH"Ansible プレイブックまたは Ansible プレイブックを使って自分で試してみることができます。

- name: check modinfo
  shell: |
    echo $PATH

# "stdout": "/usr/local/bin:/usr/bin:/bin:/usr/games",

おすすめ記事