-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Finalise standardisations remaining from the _mapdata
implementation
#205
Comments
Hello. For Looking at |
@baby-gnu The whole discussion started when I was testing this
Of course, would just need to apply that for Windows only. |
yes, we have some internal formulas at work only for windows machines and found an issue this way. I was wondering what's better between manage the difference in the state or the check. any preference? |
@baby-gnu Do you have a working state available? It would be useful to compare both methods. |
You can try the following: diff --git a/TEMPLATE/_mapdata/init.sls b/TEMPLATE/_mapdata/init.sls
index cfa4837..d253a3c 100644
--- a/TEMPLATE/_mapdata/init.sls
+++ b/TEMPLATE/_mapdata/init.sls
@@ -16,3 +16,11 @@
- template: jinja
- context:
map: {{ mapdata | yaml }}
+
+{%- if grains['os_family'] == 'Windows' %}
+{{ tplroot }}-mapdata-strip-newline:
+ file.replace:
+ - name: {{ output_file }}
+ - pattern: '\r'
+ - repl: ''
+{%- endif %} Here is the result when applying the
The salt/job/20200907095318212067/ret/PC-386675.example.net {
"_stamp": "2020-09-07T09:53:21.087071",
"cmd": "_return",
"fun": "state.apply",
"fun_args": [
"TEMPLATE._mapdata"
],
"id": "PC-386675.example.net",
"jid": "20200907095318212067",
"out": "highstate",
"retcode": 0,
"return": {
"file_|-TEMPLATE-mapdata-dump_|-/tmp/salt_mapdata_dump.yaml_|-managed": {
"__id__": "TEMPLATE-mapdata-dump",
"__run_num__": 0,
"__sls__": "TEMPLATE._mapdata",
"changes": {
"diff": "--- \n+++ \n@@ -1,13 +1,13 @@\n-# yamllint disable rule:indentation rule:line-length\n-# Windows-7\n----\n-added_in_defaults: defaults_value\n-config: /etc/TEMPLATE\n-pkg:\n- name: TEMPLATE\n-rootgroup: root\n-service:\n- name: TEMPLATE\n-subcomponent:\n- config: /etc/TEMPLATE-subcomponent-formula.conf\n-winner: defaults\n+# yamllint disable rule:indentation rule:line-length\r\n+# Windows-7\r\n+---\r\n+added_in_defaults: defaults_value\r\n+config: /etc/TEMPLATE\r\n+pkg:\r\n+ name: TEMPLATE\r\n+rootgroup: root\r\n+service:\r\n+ name: TEMPLATE\r\n+subcomponent:\r\n+ config: /etc/TEMPLATE-subcomponent-formula.conf\r\n+winner: defaults\r\n"
},
"comment": "File /tmp/salt_mapdata_dump.yaml updated",
"duration": 109.375,
"name": "/tmp/salt_mapdata_dump.yaml",
"result": true,
"start_time": "11:53:06.906250"
},
"file_|-TEMPLATE-mapdata-strip-newline_|-/tmp/salt_mapdata_dump.yaml_|-replace": {
"__id__": "TEMPLATE-mapdata-strip-newline",
"__run_num__": 1,
"__sls__": "TEMPLATE._mapdata",
"changes": {
"diff": "--- \n+++ \n@@ -1,13 +1,13 @@\n-# yamllint disable rule:indentation rule:line-length\r\n-# Windows-7\r\n----\r\n-added_in_defaults: defaults_value\r\n-config: /etc/TEMPLATE\r\n-pkg:\r\n- name: TEMPLATE\r\n-rootgroup: root\r\n-service:\r\n- name: TEMPLATE\r\n-subcomponent:\r\n- config: /etc/TEMPLATE-subcomponent-formula.conf\r\n-winner: defaults\r\n+# yamllint disable rule:indentation rule:line-length\n+# Windows-7\n+---\n+added_in_defaults: defaults_value\n+config: /etc/TEMPLATE\n+pkg:\n+ name: TEMPLATE\n+rootgroup: root\n+service:\n+ name: TEMPLATE\n+subcomponent:\n+ config: /etc/TEMPLATE-subcomponent-formula.conf\n+winner: defaults\n"
},
"comment": "Changes were made",
"duration": 0.0,
"name": "/tmp/salt_mapdata_dump.yaml",
"result": true,
"start_time": "11:53:07.015625"
}
},
"success": true
} |
NB: for windows I had to create the |
I finished with the following code to handle windows minions: diff --git a/TEMPLATE/_mapdata/init.sls b/TEMPLATE/_mapdata/init.sls
index cfa4837..18e96fc 100644
--- a/TEMPLATE/_mapdata/init.sls
+++ b/TEMPLATE/_mapdata/init.sls
@@ -16,3 +16,23 @@
- template: jinja
- context:
map: {{ mapdata | yaml }}
+
+{%- if grains['os_family'] == 'Windows' %}
+{#- file.directory requires an absolute path with drive letter #}
+{% set system_drive = salt['environ.get']('SYSTEMDRIVE', 'C:') %}
+{% set tmp_dir = system_drive ~ '/tmp' %}
+
+{{ tplroot }}-mapdata-tmp-file-directory:
+ file.directory:
+ - name: {{ tmp_dir }}
+ - require_in:
+ - file: {{ tplroot }}-mapdata-dump
+
+{{ tplroot }}-mapdata-strip-newline:
+ file.replace:
+ - name: {{ output_file }}
+ - pattern: '\r'
+ - repl: ''
+ - require:
+ - file: {{ tplroot }}-mapdata-dump
+{%- endif %} Unfortunately, I don't know how to run InSpec with my windows machine, so I don't know how to check if it's working correctly. |
You can run InSpec against the Windows Vagrant image used by Kitchen in some other formulas, but it hasn't been implemented in the |
I closed |
Actually, the rest are also resolved now (so I've ticked them):
Leaving this issue open for now since there may be another issue encountered when finalising situations with the v5 |
#203 has been merged but there are outstanding issues that need to be finalised, particularly when standardising across all of the formulas in our organisation (using the
ssf-formula
). Quoting the relevant comment here:The text was updated successfully, but these errors were encountered: