前提
ここに質問の内容を詳しく書いてください。
AnsibleでWindows仮想マシン接続をしたいが、hosts指定方法が分からない。
実現したいこと
ここに実現したいことを箇条書きで書いてください。
・ymlファイルでhosts指定してWindows仮想マシン接続ができるようにしたい。
・inventory構築方法、ymlファイルに組み込む方法を知りたい。
発生している問題・エラーメッセージ
以下のymlファイルをAzure CLIで実行しました。
- hosts: all
vars_prompt:- name: ansible_password
prompt: "Enter local administrator password"
ansible_user: azureuser
ansible_connection: winrm
ansible_winrm_transport: ntlm
ansible_winrm_server_cert_validation: ignore
tasks: - name: ansible_password
以下、上記を試した結果となります。
@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
- name: ansible_password
prompt: "Enter local administrator password"
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