Skip to content

module_utils/pfsense.py:PFSenseModule.php JSONDecodeError: Expecting value: line 1 column 1 (char 0) #118

@NeonixRIT

Description

@NeonixRIT

Using openstack and ansible 2.10.8 to deploy and configure some pfsense 2.6.0 instances. It seems
self.module.run_command('/usr/local/bin/php', data=cmd) has .. added to the beginning of stdout causing JSONDecoder to throw an error when trying to parse the returned json string from php. I fixed this by changing the php function to the following.

    def php(self, command):
        """ Run a command in php and return the output """
        cmd = '<?php\n'
        cmd += command
        cmd += '\n?>\n'
        (dummy, stdout, stderr) = self.module.run_command('/usr/local/bin/php', data=cmd)
        start_of_json = stdout.index('{')
        end_of_json = stdout.rindex('}') + 1
        # TODO: check stderr for errors
        return json.loads(stdout[start_of_json:end_of_json])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions