You can use the ansible.builtin.command
module to execute multiple commands by chaining them together using the command separator ;
or &&
.
Here’s an example using ;
:
- name: Execute two commands using semicolon
ansible.builtin.command: "command1 ; command2"
In this example, command1
will be executed first, followed by command2
.
And here’s an example using &&
:
- name: Execute two commands using logical AND
ansible.builtin.command: "command1 && command2"
In this example, command2
will only be executed if command1
exits with a success status code (i.e., a return code of 0). If command1
exits with a non-zero status code (indicating an error), then command2
will not be executed.
You can replace command1
and command2
with your own commands. Remember to enclose them in quotes and separate them with the appropriate command separator.