Skip to content

Instantly share code, notes, and snippets.

@KeyboardInterrupt
Last active August 14, 2019 11:49
Show Gist options
  • Save KeyboardInterrupt/4d6e2be651a0d5d646df8070ddbb20dd to your computer and use it in GitHub Desktop.
Save KeyboardInterrupt/4d6e2be651a0d5d646df8070ddbb20dd to your computer and use it in GitHub Desktop.

Revisions

  1. Christian S revised this gist Aug 14, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions crm.fact
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,8 @@ xml_config = subprocess.check_output(
    xml_status = subprocess.check_output(
    ["crm_mon", "--as-xml"]
    )
    dict_config = xmltodict.parse(xml_config)
    dict_status = xmltodict.parse(xml_status)
    dict_config = xmltodict.parse(xml_config ,attr_prefix="")
    dict_status = xmltodict.parse(xml_status ,attr_prefix="")
    dict_combined = dict_config.copy()
    dict_combined.update(dict_status)

  2. Christian S created this gist Aug 14, 2019.
    32 changes: 32 additions & 0 deletions crm.fact
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/usr/bin/python
    #
    # Description:
    # This script is a custom fact for ansible that turns `crm configure show` and `crm_mon`
    # output into a fact that can be used in Ansible. i.E. to iterate over all
    # nodes in a cluster, check for the location of a resource and so on.
    #
    # Dependencies:
    # - xmltodict - https://pypi.org/project/xmltodict/
    #
    # Author:
    # KeyboardInterrupt - www.keyboardinterrupt.com
    #

    import xmltodict
    import json
    import subprocess

    xml_config = subprocess.check_output(
    ["crm", "configure", "show", "xml"]
    )
    xml_status = subprocess.check_output(
    ["crm_mon", "--as-xml"]
    )
    dict_config = xmltodict.parse(xml_config)
    dict_status = xmltodict.parse(xml_status)
    dict_combined = dict_config.copy()
    dict_combined.update(dict_status)

    json_combined = json.dumps(dict_combined)

    print(json_combined)