Get all discovery rules

Problem:
I am looking for a way to get the info about all the discovery rules in my foreman. There seems to be no api or ansible module to get it.
I went through the documentation but couldn’t find anything.
My main purpose is to get the names of all the discovery rules and delete it using ansible task.

Thanks

Found it.

We can use theforeman.foreman.resource_info module of Ansible and set resource to discovery_rules.

Example ansible task:

tasks:    
   - name: "Get all discovery rules with 'name ~ Default'"
      theforeman.foreman.resource_info:
        username: "{{ foreman_username }}"
        password: "{{ foreman_password }}"
        server_url: "{{ foreman_url }}"
        validate_certs : "{{ foreman_validate_certs }}"
        resource: discovery_rules
        full_details: true
      register: ALL_DISCOVERY_RULES
3 Likes