yavdr / yavdr-ansible

ansible playbooks for yaVDR
GNU General Public License v3.0
11 stars 10 forks source link

'Cant open display' by xrandr #3

Closed LuigiDC closed 6 years ago

LuigiDC commented 6 years ago

The command xrandr -q executed by the xorg detection creates the error 'Cant open display'. Therefore the video modes are not correctly detected for the generation of the xorg.conf.

Actual solution: My workoaround was to add a envvar export DISPLAY=:0 to the ./bashrc to get the output details from xrandr -q.

Netherless the xorg.conf doesnt contain the new entries automatically.

seahawk1986 commented 6 years ago

If you are referring to roles/yavdr-xorg/read_xrandr.py - this script is not used by ansible (it was an early draft I forgot to remove from the git repository).

https://github.com/yavdr/yavdr-ansible/blob/master/roles/yavdr-xorg/tasks/detect-xorg.yml#L43 calls https://github.com/yavdr/yavdr-ansible/blob/master/library/xrandr_facts.py

LuigiDC commented 6 years ago

I saw it already. Just used it to debug my output and to make the first steps with yavdr-ansible + python. I'm already analyzing and testing the skripts which are called by detect-xorg.yml. Netherless, detect-xorg.ymlseems to call xrandr_facts.py which itselfs calls xrandr --verbose in an subprocess for a more detailed output. I would guess that it also requires the DISPLAY=:0 environment.

seahawk1986 commented 6 years ago

display is set to :0 by default: https://github.com/yavdr/yavdr-ansible/blob/master/library/xrandr_facts.py#L60 and used as an argument (resulting in -d :0) for the xrandr call: https://github.com/yavdr/yavdr-ansible/blob/master/library/xrandr_facts.py#L263

LuigiDC commented 6 years ago

Correctly. I removed the envvar and tried to localy call the python script in the bash. I'm getting the some errors:

  1. If the ansible module declaration remains in the script the whole script hangs up. (I got the problem in each module)
  2. If i remove the parts and replace them with the inline commando the request results to
xrandr: unrecognized option '-d :0 --verbose'
Try 'xrandr --help' for more information.
Traceback (most recent call last):
  File "/home/luigi/yavdr-ansible/library/xrandr_facts.py", line 263, in <module>
    d = subprocess.check_output(['xrandr', '-d :0 --verbose'], universal_newlines=True).splitlines()
  File "/usr/lib/python2.7/subprocess.py", line 574, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['xrandr', '-d :0 --verbose']' returned non-zero exit status 1
  1. xrandr -d :0 --verbose called directly through the shell leads into correct output.
xrandr -d :0 --verbose
Screen 0: minimum 8 x 8, current 1280 x 1024, maximum 16384 x 16384
VGA-0 disconnected (normal left inverted right x axis y axis)
        Identifier: 0x27e
        Timestamp:  17047
        Subpixel:   unknown
        Clones:
        CRTCs:      0 1 2 3
        Transform:  1.000000 0.000000 0.000000
                    0.000000 1.000000 0.000000
                    0.000000 0.000000 1.000000
                   filter:
        CscMatrix: 65536 0 0 0 0 65536 0 0 0 0 65536 0
.....
flensrocker commented 6 years ago

I think that should be ['xrandr', '-d :0', '--verbose'].

LuigiDC commented 6 years ago

Still the same problem. I tried today the command on an virtual machine and it worked as expected. I changed the command to

d = subprocess.check_output(['xrandr -d :0 --verbose'], shell=True, universal_newlines=True).splitlines()

and the command was executed without errors.

Edit 1: The rest of the script worked as expected except the following points.

Edit 2: The correct line should be (of course):

d = subprocess.check_output(['xrandr', '-d', ':0', '--verbose'], universal_newlines=True).splitlines()

and it worked.

LuigiDC commented 6 years ago

As i can see problem lies in the line

module = AnsibleModule(argument_spec=ARG_SPECS, supports_check_mode=False,)

The module hangs up during the initial. If i break the execution the following error occurs in the debugger

module = AnsibleModule(argument_spec=ARG_SPECS, supports_check_mode=False,)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/ansible/module_utils/basic.py", line 701, in __init__
    self._load_params()
  File "/usr/lib/python2.7/dist-packages/ansible/module_utils/basic.py", line 1768, in _load_params
    self.params = _load_params()
  File "/usr/lib/python2.7/dist-packages/ansible/module_utils/basic.py", line 603, in _load_params
    buffer = sys.stdin.read()

If the module isnt initialized the xrandrcall gets no display port. I can replace all vars which depends on module.* by the dictionary value directly like

ARG_SPECS['display']['default']

and it works.

seahawk1986 commented 6 years ago

Have a look at https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html - you need a special environment to run Ansible modules, the python Interpreter on it's own is not enough.

LuigiDC commented 6 years ago

Right. Now runs like a charm.