dell / dellemc-openmanage-ansible-modules

Dell OpenManage Ansible Modules
GNU General Public License v3.0
335 stars 163 forks source link

OME Configuration Compliance Template #339

Closed ImranJMughal closed 2 years ago

ImranJMughal commented 2 years ago
Question

Is there any playbook for configuration compliance templates. I want to import a template from an XML file to each of our OME instances. To confirm this isn't the same as ome_template.

Details

image

image

anupamaloke commented 2 years ago

@ImranJMughal, you can use ome_template module to create the configuration compliance template. See below example playbook that uses a reference device to create a configuration compliance template. You can also choose to import a SCP XML file to create a compliance template. In order to create a compliance template, you will have to set the template_view_type to Compliance.

  tasks:
  - name: create a compliance template
    dellemc.openmanage.ome_template:
      hostname: "{{ inventory_hostname }}"
      username: "{{ ome_username }}"
      password: "{{ ome_password }}"
      command: "create"
      device_service_tag: "ABC1234"
      template_view_type: "Compliance"
      attributes:
        Name: "Ansible Demo Configuration Compliance"
        Description: "Ansible Demo Configuration Compliance Template"
        Fqdds: "BIOS"   <========= Default is "ALL". 
        TypeId: 2           <========= Server is "2", Chassis is "4" and IO Module is "3"
    register: result

  - name: get the job ID
    dellemc.openmanage.ome_template_info:
      hostname: "{{ inventory_hostname }}"
      username: "{{ ome_username }}"
      password: "{{ ome_password }}"
      template_id: "{{ result.return_id }}"
    register: template_info

  - name: Track job till completion
    dellemc.openmanage.ome_job_info:
      hostname: "{{ inventory_hostname }}"
      username: "{{ ome_username }}"
      password: "{{ ome_password }}"
      job_id: "{{ template_info.template_info[inventory_hostname].TaskId }}"
    register: job_result
    failed_when: job_result.job_info.LastRunStatus.Name == 'Failed'
    changed_when: job_result.job_info.LastRunStatus.Name == 'Completed'
    until: job_result.job_info.LastRunStatus.Name == 'Completed' or job_result.job_info.LastRunStatus.Name == 'Failed'
    retries: 25
    delay: 10
anupamaloke commented 2 years ago

@sachin-apa, @jagadeeshnv it would be good to update the EXAMPLES section in the module documentation as well as the example playbooks on how to create configuration compliance templates from a reference device or by importing a SCP file.

ImranJMughal commented 2 years ago

Hey thanks guys, i was just testing it with Anupam.

So this works for import from a reference device

  - name: create a compliance template
    dellemc.openmanage.ome_template:
      hostname: "{{ inventory_hostname }}"
      username: "{{ ome_username }}"
      password: "{{ ome_password }}"
      command: "create"
      device_service_tag: "ABC1234"
      template_view_type: "Compliance"
      attributes:
        Name: "Ansible Demo Configuration Compliance"
        Description: "Ansible Demo Configuration Compliance Template"
        Fqdds: "BIOS"   <========= Default is "ALL". 
        TypeId: 2           <========= Server is "2", Chassis is "4" and IO Module is "3"
    register: result

For import from XML you need to use Type instead of TypeId. This should be standardised to avoid confusion

  - name: create a compliance template
    dellemc.openmanage.ome_template:
      hostname: "{{ inventory_hostname }}"
      username: "{{ ome_username }}"
      password: "{{ ome_password }}"
      command: "import"
      template_view_type: "Compliance"
      attributes:
        Name: "Ansible Demo Configuration Compliance"
         Content: "{{ lookup('ansible.builtin.file', './test.xml') }}"
        Type: 2
    register: result