如何通过Ansible Playbook或参数禁用SSH的-tt与ControlPath参数?
Solution to Disable
-tt and ControlPath in Ansible SSH Commands I've run into similar connection issues with Ansible's default SSH control parameters before, so let's tackle this with your priority in mind—fixing it directly in the playbook first:
1. Modify the Playbook to Disable Both Parameters
You can add Ansible-specific variables right in your play to turn off the -tt flag and skip the ControlPath configuration. Here's your updated playbook:
- name: Play 2- Configure Source nodes hosts: all user: root ignore_errors: yes gather_facts: false vars: # Disable the `-tt` (force tty) parameter ansible_ssh_use_tty: no # Disable ControlPath by setting it to an empty string ansible_ssh_control_path: "" tasks: - name: Get HTTPD userid on server raw: id mwweb || id webadm || ls -ld /web - name: Get OHS userid on server raw: id mwweb
How This Works:
ansible_ssh_use_tty: no: This tells Ansible not to append the-ttflag to the SSH command, which you already confirmed resolves half the issue.ansible_ssh_control_path: "": Setting this variable to an empty string overrides Ansible's default control path logic, so it won't include the-o ControlPath=...parameter in the generated SSH command. This effectively disables SSH connection multiplexing for this play.
2. Fallback: Command-Line Parameters (If Playbook Changes Aren't Feasible)
If you can't modify the playbook directly for any reason, pass both variables via the command line when running ansible-playbook:
ansible-playbook -i 10.9.88.205, -f 5 testpython.yml -vvvv -e "ansible_ssh_use_tty=no ansible_ssh_control_path="""
Note the triple quotes around the empty string for ansible_ssh_control_path—this ensures the shell passes an empty value to Ansible instead of ignoring the variable entirely.
Why These Parameters Cause Issues
- The
-ttflag forces SSH to allocate a pseudo-terminal, which can lead to unexpected behavior in non-interactive environments like Jenkins (where no real terminal is attached). ControlPathenables SSH connection multiplexing, but if the path points to a directory the Jenkins-run Ansible user lacks write access to, or if stale control sockets are left behind, it can break connections entirely. Disabling it skips this multiplexing layer to avoid such conflicts.
内容的提问来源于stack exchange,提问作者Ashar
相关产品推荐
相关产品推荐

