3
votes

I need to create a default profile for firefox on some of my servers which requires the DISPLAY number. I can't figure out how to do this with Ansible. I've been trying to get X11 forwarding working, but have not been successful. I am not allowed to alter the SSH configuration, so I can't enable X11 from there. How can I do this with Ansible?

I've tried the following:

  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

I can ssh -X user@as1 and successfully run: firefox -createprofile "default /opt/profiles/default"

There must be a way to do this, but I'm not sure what else to try.

2

2 Answers

0
votes

You can run firedox in headless mode (so no need to have X11 forwarding) this way

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

So you can implement this way in ansible

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

(I prefer to use command module over shell when there is no need for shell feature)

0
votes

In general, not just for the particular firefox case, adding the "-o ForwardX11=yes" option to the ssh argument should do the trick. You can do this:

  1. setting the ANSIBLE_SSH_ARGS from command line, as in:
ANSIBLE_SSH_ARGS='-C -o ForwardX11=yes -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no' ansible-playbook -i hosts.ini test.yml
  1. Update the ansible.cfg file:
[ssh_connection]
    ssh_args =  -C -o ForwardX11=yes -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no
  1. My preferred way, setting the ansible_ssh_extra_args in the hosts.ini file, for example:
    [all]
    hostname ansible_host=10.0.0.1 ansible_user=user ansible_ssh_extra_args='-o ForwardX11=yes'