Configuring the Playbooks


This section describes how to use the user-defined playbooks and the pre-built playbooks.

How to Use the User-defined Playbooks

Add/Edit a Playbook

Step 1        Add a playbook.

   a)  Select Automation > Playbooks.

   b)  Click the button  to add a new playbook.

   c)  Enter the playbook name and description in the pop-up “Ansible Playbook” box. The playbook name will be used as the main playbook folder name. Then click “Next” to enter "Ansible Playbook" page.

  NOTE:

  The playbook name should be unique.

  d)  In the "Ansible Playbook" page, you can Add/Delete file or Add/Delete folder.

•   Add file

    Select the parent folder first, then click the file add button . Enter the file name in the model and then click “Add”.

•   Add folder

    Select the parent folder first, then click the folder add button . Enter the folder name in the model and then click “Add”.

•   Delete file/folder

    Select the folder or file, then click the delete button . Then confirm the action in the model.

       e)  Edit the playbook file contents in the edit box on the right side of the page. Then click " Save All " button after the editing is completed.

    The new playbook will appear in the "Ansible Playbook List".

Step 2        Edit a playbook.

   Click “Edit” button in the playbook table in “Operation” column to edit a playbook.

   NOTE:

   Don’t forget to click the “Save All” button to save all the configurations after the editing is completed.

Step 3        Remove a playbook.

   Click the “Remove” button  in the playbook table in “Operation” column to delete a playbook.

   Then confirm the action in the pop-up Are you sure? dialog box.

   NOTE: When the playbook is deleted, the related jobs and task results will also be removed.

Save As a Playbook (version control)

Click "Save As" button in the playbook table to create a copy of the current playbook. This function can be used to back up the playbook or to create a different version of the playbook.

The playbook name field will be automatically filled with current playbook name plus with current daytime. User can also rename the new copy playbook.

Export / Import a Playbook

AmpCon supports to export and import a playbook, the following procedure shows how to export or import a playbook:

Step 1        Export a playbook.

   Click the “Export” button in the playbook table.

   The zip file will be automatically downloaded to the local system.

Step 2        Import a playbook.

   Click “Import” button on the left side.

   Enter the new playbook name, description, then choose a zip playbook file exported earlier.

   Then Click “Import” to upload the new zip playbook.

   NOTE: The entered playbook name should be unique.


Run a Playbook

When running Ansible playbooks, AmpCon executes the defined tasks in file playbook.yml on the targeted switches. This section describes how to run the Ansible playbooks.

Step 1        Click “Run” button in the playbook table.

Step 2        Specify the main playbook file in the modal first, then select switches or groups on which to run the playbook, then click “Next” button.

Step 3        Edit the ansible option or extra variables in JSON format for running playbook, then click “Next” button.

When running a playbook, there are some ansible options that can be set. You can also define extra variables in this box. If the options are not set, the default running options are used. The default ansible options are as follows:

options = Options(
            verbosity=4,
            listhosts=None,
            subset=None,
            module_path=['/usr/share/automation/server/ansible_lib/'],
            extra_vars=[],
            forks=5,
            ask_vault_pass=False,
            vault_password_files=[],
            new_vault_password_files=[],
            vault_ids=[],
            new_vault_id=None,
            tags=['all'],
            skip_tags=[],
            ask_pass=False,
            private_key_file='',
            connection='smart',
            timeout=10,
           ssh_common_args='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no',
            sftp_extra_args='',
            scp_extra_args='',
            ssh_extra_args='',
            sudo=False,
            sudo_user=None,
            su=False,
            su_user=None,
            become=False,
            become_method='sudo',
            become_user='root',
            ask_sudo_pass=False,
            ask_su_pass=False,
            become_ask_pass=False,
            check=False,
            syntax=None,
            diff=False,
            force_handlers=False,
            flush_cache=None,
            listtasks=None,
            listtags=None,
            step=None,
            start_at_task=None,
            passwords=None,
            host_key_checking=False,
            command_warnings=False,
            roles_path='/usr/share/automation/server/ansible_playbook/',
            gathering="smart"
        )

   NOTE:

   For role_path option, it is the same path as the playbook save folder path, so user can easily use the created/imported playbook as ansible role.

Step 4        In the pop-up “Run Playbook” box, select the schedule type from one of “Run Now”, “One Time” or “Scheduled”.

   •   If “Run Now” is selected.

   The playbook will be executed immediately.

   •   If “One Time” is selected.

   Set a “Start Time” and “End Time”, then the playbook will start running at the specified “Start Time”. When setting the time, the “End Time” should be later than the “Start Time”.

   •   If “Scheduled” is selected.

   The “Schedule” field should be entered with valid crontab expression.

   Then the playbook will be triggered by the given crontab expression.

      NOTE:

  • Run playbook function will ignore the specified host file in playbook, which is replaced by the selected switches/groups.
  • Run playbook function will use the username/password configured in Settings > System Configuration when executing the defined tasks on the target switches.
  • When running a playbook, the user configured ansible options in Step 3 can override the default options.

How to Use the Pre-built Playbooks

1.  By default, it will not show the internal pre-built playbooks in playbook list.


     User can enable “Show Internal Playbook” to check the internal pre-built playbooks.

The pre-built playbooks will have a badge “Internal” after the playbook name.

 


2.   Pre-built internal playbooks support “View”, “Save As”, “Export” actions in “Operation” column.

 


3.   Users can update the latest pre-built playbooks from Gitlab by clicking the button “Update Internal Playbooks” (Github URL: https://github.com/pica8/Ansible/tree/main/playbooks).

How to Use Ansible-Galaxy to download roles / collections and include them in playbook


Ansible-Galaxy Usage Guide.docx


Copyright © 2024 Pica8 Inc. All Rights Reserved.