Sceptre/sceptre

The dump config command is not loading the j2_environment

alex-harvey-z3q opened this issue · 1 comments

Subject of the issue

Given a stack with custom j2_environment, this is not loaded or available during the dump config command.

Your environment

  • version of sceptre - latest
  • version of python - 3.10
  • which OS/distro - Debian

Steps to reproduce

Create a stack that has a custom Jinja filter called in its config. Try dump config. A message like this will be seen:

"No filter named '<some_filter>'."

Try sceptre generate; that should work fine.

I spent some time trying to understand the root cause of this.

It seems that the implementation of dump config depends on the public read method of the ConfigReader class. However, the read method does not seem to be implemented correctly as a public method and can actually only be called privately by the construct_stacks method.

The problem here is that read seems to be called iteratively and the final config is built up stack by stack within stack group. The read method's second optional argument allows a work-in-progress config to be passed in.

I found that if I hard coded the config on line 1154 of actions.py in the dump_config method of the StackActions class like this:

1148     @add_stack_hooks
1149     def dump_config(self, config_reader: ConfigReader):
1150         """
1151         Dump the config for a stack.
1152         """
1153         stack_path = normalise_path(self.stack.name + ".yaml")
1154         #return_val = config_reader.read(stack_path)
1155         return_val = config_reader.read(stack_path, {"j2_environment": {'extensions': ['jinja2_ansible_filters.AnsibleCoreFiltersExtension']}})
1156         return return_val

... this 'fixes' the issue.

Some significant refactoring of the SceptrePlan and ConfigReader interactions is needed to fix this properly.

Cc @jtfalkenstein @mrowlingfox