- 1 year ago
ansible win_shell module to run 2 seperate commands
To run two separate commands using the win_shell
module in Ansible, you can provide the commands as a single string with appropriate line breaks or separate them using the &&
operator. Here are examples of both approaches:
- Using line breaks:
yaml- name: Run multiple commands using line breaks
win_shell: |
command1
command2
In this example, command1
and command2
are separate commands written in individual lines under the win_shell
task. Each command will be executed sequentially.
- Using the
&&
operator:
yaml- name: Run multiple commands using the && operator
win_shell: "command1 && command2"
In this example, the commands command1
and command2
are joined together using the &&
operator. The &&
operator ensures that the second command (command2
) is only executed if the first command (command1
) succeeds.
Choose the approach that best suits your requirements and the context of your Ansible playbook. Remember to properly format the YAML syntax and take care with the indentation in your playbook.