Ansible与SSH X11转发

4

我需要在一些服务器上为Firefox创建一个默认档案,这需要 DISPLAY 数字。我无法通过 Ansible 实现这个目标。我一直试图使 X11 转发工作,但一直没有成功。由于不允许更改 SSH 配置,因此无法从那里启用 X11。请问如何使用 Ansible 来实现这一点?

我已经尝试了以下方法:

  1. - name: Create default profile  
      shell: firefox -createprofile "default /opt/profiles/default"
    

    and setting the ssh_args in ansible.cfg to: ssh_args= -X

    This fails with:

    Failed to connect to the host via ssh: ssh: connect to host as1 port 22: No route to host

  2. - name: Create default profile  
      shell: |  
        export DISPLAY=:0.0  
        firefox -createprofile "default /opt/profiles/default"
    

    without adding the ssh_args = -X option

    This fails with:

    No protocol specified, Error: cannot open display: :0.0

我可以使用ssh -X user@as1成功运行以下命令:firefox -createprofile "default /opt/profiles/default"

一定有其他方法可以实现这个功能,但我不确定还可以尝试什么。

2个回答

0
一般而言,不仅仅是针对Firefox的情况,在ssh参数中添加“-o ForwardX11=yes”选项应该就可以解决问题。 您可以这样做:
  1. 从命令行设置ANSIBLE_SSH_ARGS,例如:
ANSIBLE_SSH_ARGS='-C -o ForwardX11=yes -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no' ansible-playbook -i hosts.ini test.yml

2. 更新ansible.cfg文件:
[ssh_connection]
    ssh_args =  -C -o ForwardX11=yes -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no

我的首选方法是在hosts.ini文件中设置ansible_ssh_extra_args,例如:
    [all]
    hostname ansible_host=10.0.0.1 ansible_user=user ansible_ssh_extra_args='-o ForwardX11=yes'

0

您可以以无头模式运行Firefox(因此无需进行X11转发)的方式如下:

firefox -headless -CreateProfile "default /opt/profiles/default"

所以你可以在ansible中这样实现

- name: Create default profile  
  command: firefox -headless -createprofile "default /opt/profiles/default"

当不需要使用shell功能时,我更喜欢使用命令模块。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接