Run your playbook automation to test behavior

Run your playbook using two methods provided by the Ansible VS Code extension.

Procedure

The Ansible VS Code extension provides two options to run your playbook:
  • ansible-playbook runs the playbook on your local machine using Ansible Core.
  • ansible-navigator runs the playbook in an execution environment in the same manner that Ansible Automation Platform runs an automation job. You specify the base image for the execution environment in the Ansible extension settings.

Run your playbook with ansible-playbook

You can run your Ansible playbook locally by using the ansible-playbook command directly within the VS Code extension.

Procedure

To run a playbook, right-click the playbook name in the Explorer pane, then select Run Ansible Playbook via > Run playbook via ansible-playbook.

Run playbook via ansible-playbook

The output is displayed in the Terminal tab of the VS Code terminal. The ok=2 and failed=0 messages indicate that the playbook ran successfully.

Success message for ansible-playbook execution

Run your playbook with ansible-navigator

You can run an Ansible playbook through ansible-navigator by right-clicking the playbook name in the Explorer pane. This procedure explains how to view the playbook’s output and navigate the results for each play and task within the terminal.

Before you begin

  • You enabled the use of an execution environment in the Ansible extension settings.
  • You entered the path or URL for the execution environment image in the Ansible extension settings.

Procedure

  1. To run a playbook, right-click the playbook name in the Explorer pane, then select Run Ansible Playbook via > Run playbook via ansible-navigator run.
  2. View the output in the Terminal tab of the VS Code terminal. The Successful status indicates that the playbook ran successfully.

    Output for ansible-navigator execution

  3. Enter the number next to a play to step into the play results. The example playbook only contains one play. Enter 0 to view the status of the tasks executed in the play.

    Tasks in ansible-navigator output

    Type the number next to a task to review the task results.

Publish and run your playbook automation

The following procedures describe how to deploy your new playbooks in your instance of Ansible Automation Platform so that you can use them to run automation jobs.

Save your project in SCM

Save your playbook project as a repository in your source control management system, for example GitHub.

Procedure

  1. Initialize your project directory as a git repository.
  2. Push your project up to a source control system such as GitHub.

Run your playbook in Ansible Automation Platform

To run your playbook in Ansible Automation Platform, you must create a project in automation controller for the repository where you stored your playbook project. You can then create a job template for each playbook from the project.

Procedure

  1. In a browser, log in to automation controller.
  2. Configure a Source Control credential type for your source control system if necessary. See the Creating new credentials section of Using automation execution for more details.
  3. In automation controller, create a project for the GitHub repository where you stored your playbook project. Refer to the Projects chapter of Using automation execution.
  4. Create a job template that uses a playbook from the project that you created. Refer to the Job Templates chapter of Using automation execution.
  5. Run your playbook from automation controller by launching the job template. Refer to the Launching a job template section of Using automation execution.