@@ -0,0 +1,1932 @@
+# -*- coding: utf-8 -*-%0A'''%0AStore key/value pairs in a CSV file%0A%0A.. versionaddedd:: Carbon%0A%0AExample configuration:%0A%0A.. code-block:: yaml%0A%0A    ext_pillar:%0A      - csv: /path/to/file.csv%0A%0A    # or%0A%0A    ext_pillar:%0A      - csv:%0A          path: /path/to/file.csv%0A          namespace: 'subkey'%0A          fieldnames:%0A          - col1%0A          - col2%0A          - col2%0A%0AThe first column must be minion IDs and the first row must be dictionary keys.%0AE.g.:%0A%0A==========  =========   ======%0Aid          role        env%0A==========  =========   ======%0Ajerry       web         prod%0Astuart      web         stage%0Adave        web         qa%0Aphil        db          prod%0Akevin       db          stage%0Amike        db          qa%0A==========  =========   ======%0A%0AWill produce the following Pillar values for a minion named %22jerry%22:%0A%0A.. code-block:: python%0A%0A    %7B%0A        'role': 'web',%0A        'env': 'prod',%0A    %7D%0A'''%0Aimport csv%0A%0Aimport salt.utils%0A%0A__virtualname__ = 'csv'%0A%0A%0Adef __virtual__():%0A    return __virtualname__%0A%0A%0Adef ext_pillar(%0A        mid,%0A        pillar,%0A        path,%0A        idkey='id',%0A        namespace=None,%0A        fieldnames=None,%0A        restkey=None,%0A        restval=None,%0A        dialect='excel'):%0A    '''%0A    Read a CSV into Pillar%0A%0A    :param str path: Absolute path to a CSV file.%0A    :param str idkey: (Optional) The column name of minion IDs.%0A    :param str namespace: (Optional) A pillar key to namespace the values under.%0A    :param list fieldnames: (Optional) if the first row of the CSV is not%0A        column names they may be specified here instead.%0A    '''%0A    with salt.utils.fopen(path, 'rb') as f:%0A        sheet = csv.DictReader(f, fieldnames,%0A                restkey=restkey, restval=restval, dialect=dialect)%0A%0A        for row in sheet:%0A            if row%5Bidkey%5D == mid:%0A                if namespace:%0A                    return %7Bnamespace: row%7D%0A                else:%0A                    return row%0A%0A    return %7B%7D%0A

Add ext_pillar module for reading from CSV files (#33133)