Ansible WindowServerでカレントディレクトリを移動してコマンド、batファイルを実行する方法に関する情報です。
あるバッチファイルを実行したところ、作りの問題か、絶対パスでそのバッチファイルを実行してもNGで、エラーが返ってきました。
よって、カレントディレクトリを移動してバッチを実行してあげる必要がありました。
まず、参考になるのが公式の情報です。
win_command – Executes a command on a remote Windows node — Ansible Documentation
サンプルです。
Examples
- name: Save the result of 'whoami' in 'whoami_out'
win_command: whoami
register: whoami_out- name: Run command that only runs if folder exists and runs from a specific folder
win_command: wbadmin -backupTarget:C:\backup\
args:
chdir: C:\somedir\
creates: C:\backup\- name: Run an executable and send data to the stdin for the executable
win_command: powershell.exe -
args:
stdin: Write-Host test
もう一つ参考になる情報です。
Ho do you change directory and run a command in ansible? - Stack Overflow
- name: Running make libs to build libraries
command: make libs
args:
chdir: "{{ file_path_home }}"
when: infra_problem_dir_check.stat.exists- name: Running make clean for static tarballls
command: make clean all
args:
chdir: "{{ file_path_home }}"
when: infra_problem_dir_check.stat.exists
記述を間違えているので、修正しています。