Skip to content

Instantly share code, notes, and snippets.

@castironclay
Created January 15, 2023 03:43
Show Gist options
  • Save castironclay/186375232806b1e7fc561d4fd2411764 to your computer and use it in GitHub Desktop.
Save castironclay/186375232806b1e7fc561d4fd2411764 to your computer and use it in GitHub Desktop.
ansibe hosts using master control sockets
- name: Add frontend host
hosts: localhost
tasks:
- name: Create master control socket
shell:
cmd: "sshpass -p '{{ backend_password }}' ssh -fN -M -S /tmp/{{ backend_ip }} {{ backend_username }}@{{ backend_ip }}"
executable: /bin/bash
- name: Add frontend
add_host:
name: frontend
ansible_host: "{{ frontend_ip }}"
groups: "frontend_setup"
ansible_user: "{{ frontend_username }}"
ansible_password: "{{ frontend_password }}"
ansible_become_password: "{{ frontend_password }}"
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_common_args: "-o StrictHostKeyChecking=no -o ProxyCommand='ssh -S /tmp/{{ backend_ip }} -W %h:%p -q {{ backend_username }}@{{ backend_ip }}'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment