質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

bash

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Ansible

Ansibleは、Python で書かれたサーバーの設定を管理するための 構成管理ツールです。

Q&A

0回答

941閲覧

Ansibleのホスト指定とインベントリー構築方法について

fujimegu

総合スコア0

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

bash

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Ansible

Ansibleは、Python で書かれたサーバーの設定を管理するための 構成管理ツールです。

0グッド

0クリップ

投稿2022/08/12 02:51

前提

ここに質問の内容を詳しく書いてください。
AnsibleでWindows仮想マシン接続をしたいが、hosts指定方法が分からない。

実現したいこと

ここに実現したいことを箇条書きで書いてください。
・ymlファイルでhosts指定してWindows仮想マシン接続ができるようにしたい。
・inventory構築方法、ymlファイルに組み込む方法を知りたい。

発生している問題・エラーメッセージ

以下のymlファイルをAzure CLIで実行しました。

  • hosts: all
    vars_prompt:
    • name: ansible_password
      prompt: "Enter local administrator password"
    vars:
    ansible_user: azureuser
    ansible_connection: winrm
    ansible_winrm_transport: ntlm
    ansible_winrm_server_cert_validation: ignore
    tasks:

以下、上記を試した結果となります。

@Azure:~/clouddrive$ ansible-playbook connect_azure_windows_vm_2.yml -i
20.243.49.174, --check
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the
controller starting with Ansible 2.12. Current version: 3.7.3 (default,
Jan 22 2021,
20:04:44) [GCC 8.3.0]. This feature will be removed from ansible-core in
version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
ERROR! We were unable to read either as JSON nor YAML, these are the
errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.
did not find expected '-' indicator

The error appears to be in '/usr/csuser/clouddrive/connect_azure_windows
_vm_2.yml': line 5, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- inventory_test.yml

vars_prompt:
^ here

該当のソースコード

ソースコード

試したこと

ymlファイルを修正しました。インベントリーの構築方法が分からなかったので、
変数指定の要領で "inventory_test.yml" を作り、その中にホストを指定しまし
た。↓

  • hosts: localhost
    vars_files:
    • inventory_test.yml
    vars_prompt:
    • name: ansible_password
      prompt: "Enter local administrator password"
    vars:
    ansible_user: azureuser
    ansible_connection: winrm
    ansible_winrm_transport: ntlm
    ansible_winrm_server_cert_validation: ignore
    tasks:

@Azure:~/clouddrive$ ansible-playbook connect_azure_windows_vm_2.yml --
check
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the
controller starting with Ansible 2.12. Current version: 3.7.3 (default,
Jan 22 2021,
20:04:44) [GCC 8.3.0]. This feature will be removed from ansible-core in
version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available.
Note that the implicit localhost does not match 'all'
Enter local administrator password:
[WARNING]: Found variable using reserved name: hosts

PLAY [localhost] *******************************************************



TASK [Gathering Facts] *************************************************



fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "ntlm:
HTTPSConnectionPool(host='127.0.0.1', port=5986): Max retries exceeded
with url: /wsman (Caused by NewConnectionError('<urllib3.connection.
HTTPSConnection object at 0x7f9e3df7a710>: Failed to establish a new
connection: [Errno 111] Connection refused'))", "unreachable": true}

PLAY RECAP *************************************************************



localhost : ok=0 changed=0 unreachable=1
failed=0 skipped=0 rescued=0 ignored=0

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

参考にした資料は以下となります。
Microsoft公式ドキュメント
https://docs.microsoft.com/ja-jp/azure/developer/ansible/vm-configure-windows?tabs=ansible

イベントリー構築方法
https://docs.ansible.com/ansible/2.9_ja/user_guide/intro_inventory.html

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yabusakadeny

2022/08/14 00:41

お手数ですが、まず、最初に実行したPlyaobook の内容を正確に貼っていただけますでしょうか。 YAMLの内容をそのまま貼ると、意図しない書式変換がされてしまうので、markdownの、[コードを貼り付ける書式内](https://teratail.com/help#about-markdown)にYMALを貼り付けてください。 うまくはれた場合は、以下のようになるはずです。(あくまで例です) ```yaml --- - hosts: all vars_prompt: - name: ansible_password prompt: "Enter local administrator password" vars: ansible_user: azureuser ansible_connection: winrm ansible_winrm_transport: ntlm ansible_winrm_server_cert_validation: ignore tasks: - name: Test connection win_ping: ``` なお、最初のエラーは、インベントリーとは直接関係ないようです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問