ansible replace line in settings.js for nodered

Viewed 29

Trying to enable projects in the nodered settings.js file

Under projects need to changed enabled:false to equal enabled:true

I've tried various versions of lineinfile with regex but haven't quite hit on one that works. Thanks for any tips!

The releveant portion is

editorTheme: {
    /** The following property can be used to set a custom theme for the editor.
     * See https://github.com/node-red-contrib-themes/theme-collection for
     * a collection of themes to chose from.
     */
    //theme: "",

    /** To disable the 'Welcome to Node-RED' tour that is displayed the first
     * time you access the editor for each release of Node-RED, set this to false
     */
    //tours: false,

    palette: {
        /** The following property can be used to order the categories in the editor
         * palette. If a node's category is not in the list, the category will get
         * added to the end of the palette.
         * If not set, the following default order is used:
         */
        //categories: ['subflows', 'common', 'function', 'network', 'sequence', 'parser', 'storage'],
    },

    projects: {
        /** To enable the Projects feature, set this value to true */
        enabled: false,
        workflow: {
            /** Set the default projects workflow mode.
             *  - manual - you must manually commit changes
             *  - auto - changes are automatically committed
             * This can be overridden per-user from the 'Git config'
             * section of 'User Settings' within the editor
             */
            mode: "manual"
        }
    },

    codeEditor: {
        /** Select the text editor component used by the editor.
         * Defaults to "ace", but can be set to "ace" or "monaco"
         */
        lib: "ace",
        options: {
            /** The follow options only apply if the editor is set to "monaco"
             *
             * theme - must match the file name of a theme in
             * packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/theme
             * e.g. "tomorrow-night", "upstream-sunburst", "github", "my-theme"
             */
            theme: "vs",
            /** other overrides can be set e.g. fontSize, fontFamily, fontLigatures etc.
             * for the full list, see https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandaloneeditorconstructionoptions.html
             */
            //fontSize: 14,
            //fontFamily: "Cascadia Code, Fira Code, Consolas, 'Courier New', monospace",
            //fontLigatures: true,
        }
    }
},
3 Answers

could you try this?

- name: Enable false to true conversion
  replace:
    path: /path_way
    regexp: 'enabled: false,'
    replace: 'enabled: true,'

I got it to work with this

  - name: Replace projects enabled with true
  replace:
    path: "/home/nodered/{{  nodered_instance  }}/data/settings.js"
    regexp: 'projects:([\s\S]*)workflow:'
    replace: 'projects: { enabled: true, workflow:'

But I'm going to keep trying with a before and after

I like this method better

 - name: Replace projects enabled with true
 replace:
  path: "/home/nodered/{{  nodered_instance  }}/data/settings.js"
  after: 'projects: {'
  before: 'workflow: {'
  regexp: '\benabled: false\b'
  replace: 'enabled: true'
Related