AWX Dynamic Inventory plugin for cobbler

Here is my guide on how to import systems/hosts from cobbler.

Step 1: Create a Custom Credential Type

create inventories/cobbler_inventory.py in your repo and sync the project.

Step 1: Create a Custom Credential Type

  1. Navigate to the AWX Web Interface:
    • Go to Administration > Credential Types and click on Add.
  2. Configure the Custom Credential Type:
    • Name: Give your credential type a name (e.g., Cobbler API Credential).
    • Description: Provide a description if needed.
    • Input Configuration: Define the fields for your custom credential. Here’s an example configuration:YAML

Injector Configuration: Define how these fields will be injected into the environment:YAML

Save the Custom Credential Type.

Step 2: Create a Credential Using the Custom Type

  1. Navigate to Credentials:
    • Go to Credentials and click on Add.
  2. Configure the Credential:
    • Name: Give your credential a name (e.g., Cobbler API Credential).
    • Credential Type: Select the custom credential type you just created.
    • Fields: Fill in the Cobbler server URL, username, and password.
  3. Save the Credential.

Step 3: Use the Custom Credential in Your Inventory Source

  1. Navigate to Your Inventory:
    • Go to Inventories and select your inventory or create one for cobbler.
  2. Add/Edit the Inventory Source:
    • Go to the Sources tab and edit your custom script source.
  3. Associate the Credential:
    • Under Credentials, add the custom credential you created.
  4. Set Environment Variables:
    • In the Environment Variables section, set the variables to use the credentials:JSON
      { "COBBLER_URL": "{{ host }}", "COBBLER_USER": "{{ username }}", "COBBLER_PASS": "{{ password }}" }

Step 4: Sync the Inventory

  • Save the changes and click on Sync to fetch the inventory using the credentials stored in AWX.

If successful, go to Hosts tab and you will see the imported hosts from cobbler.

By following these steps, you can securely use AWX credentials in your cobbler_inventory.py script without hardcoding sensitive information.

Would you like more detailed steps on any of these processes or help with something else?iled steps on any of these processes or help with something else?

Example Playbook using Cobbler inventory

Create a playbook file, for example, deploy.yml

Running the Playbook in AWX

  1. Create a Job Template:
    • Go to Templates and click on Add to create a new job template.
    • Fill in the necessary details like the name, inventory (select the one with Cobbler hosts), and project.
  2. Select the Playbook:
    • Choose the deploy.yml playbook you created.
  3. Run the Job:
    • Save the job template and click on Launch to run the playbook against the hosts imported from Cobbler.

Command Line Example

If you prefer to run the playbook from the command line, you can use the following command:

Replace /path/to/cobbler_inventory.py with the path to your dynamic inventory script.

This setup will ensure that your playbook runs against the hosts imported from Cobbler, performing tasks like installing Apache, starting the service, and deploying application files.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *