6 Working with the Command-Line Interface

You can use the command-line interface to manage collections and ansible roles.

Installing the Command-Line Interface

The Command-Line interface is installed on the Private Automation Hub deployment host when you install the Private Automation Hub installer. For more information about installing Private Automation Hub, see Oracle Linux Automation Manager 2: Private Automation Hub Installation Guide. You can also install the CLI alone on a separate system rather than use the CLI on the deployment host.

To install a the CLI alone on a separate system, do the following:
  1. Use the dnf config-manager tool to enable the yum repositories and do one of the following:
    • If you are using ol8_UEK6, use the following command:
      sudo dnf config-manager --enable ol8_UEKR6 ol8_appstream
    • If you are using ol8_UEK7, use the following command:
      sudo dnf config-manager --enable ol8_UEKR7 ol8_appstream
  2. Ensure that no version of ansible is present on the system. If any are, uninstall them. For example, the following shows that there are no versions of ansible installed:
    rpm -q ansible
    package ansible is not installed
  3. Install the CLI:
    sudo dnf install ansible-core

Using the Command-Line Interface

You interact with the CLI by entering commands with a series of options. The CLI command with the --help flag returns the following syntax information:
ansible-galaxy --help
usage: ansible-galaxy [-h] [--version] [-v] TYPE ...

Perform various Role and Collection related operations.

positional arguments:
  TYPE
    collection   Manage an Ansible Galaxy collection.
    role         Manage an Ansible Galaxy role.

options:
  --version      show program's version number, config file location, configured module search path, module location, executable location and exit
  -h, --help     show this help message and exit
  -v, --verbose  Causes Ansible to print more debug messages. Adding multiple -v will increase the verbosity, the builtin plugins currently evaluate up to -vvvvvv. A
                 reasonable level to start is -vvv, connection debugging might require -vvvv.
The positional arguments section lists the available resources to manage using the CLI. You can obtain additional information about these resources by adding the resource name before the --help flag. For example, the following shows actions available for the collection resource:
ansible-galaxy collection --help
usage: ansible-galaxy collection [-h] COLLECTION_ACTION ...

positional arguments:
  COLLECTION_ACTION
    download         Download collections and their dependencies as a tarball
                     for an offline install.
    init             Initialize new collection with the base structure of a
                     collection.
    build            Build an Ansible collection artifact that can be
                     published to Ansible Galaxy.
    publish          Publish a collection artifact to Ansible Galaxy.
    install          Install collection(s) from file(s), URL(s) or Ansible
                     Galaxy
    list             Show the name and version of each collection installed in
                     the collections_path.
    verify           Compare checksums with the collection(s) found on the
                     server and the installed copy. This does not verify
                     dependencies.

options:
  -h, --help         show this help message and exit

The following shows actions available for the role resource:

ansible-galaxy role --help
usage: ansible-galaxy role [-h] ROLE_ACTION ...

positional arguments:
  ROLE_ACTION
    init       Initialize new role with the base structure of a role.
    remove     Delete roles from roles_path.
    delete     Removes the role from Galaxy. It does not remove or alter the actual GitHub repository.
    list       Show the name and version of each role installed in the roles_path.
    search     Search the Galaxy database by tags, platforms, author and multiple keywords.
    import     Import a role into a galaxy server
    setup      Manage the integration between Galaxy and the given source.
    info       View more details about a specific role.
    install    Install role(s) from file(s), URL(s) or Ansible Galaxy

options:
  -h, --help   show this help message and exit

In a similar way, you can use the --help flag to obtain additional information about the available actions.