Repository: ansible/ansible

Issue:
2.4 not respecting --ssh-extra-args
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ansible-playbook, --ssh-extra-args flag

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12+ (default, Sep 17 2016, 12:08:02) [GCC 6.2.0 20160914]
```

##### CONFIGURATION
```
$ ansible-config dump --only-changed
$
```

##### OS / ENVIRONMENT
```
# uname -a
Linux jgli-PowerEdge-T20 4.8.0-22-generic #24-Ubuntu SMP Sat Oct 8 09:15:00 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.10
Release:	16.10
Codename:	yakkety
```


##### STEPS TO REPRODUCE
This works
```
# ssh rvn@172.22.0.244 -i/var/rvn/ssh/rvn
```

This does not
```
# ansible-playbook -i 172.22.0.244, config/walrus.yml --ssh-extra-args='-i/var/rvn/ssh/rvn' --user=rvn

PLAY [all] ************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************
fatal: [172.22.0.244]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true}
	to retry, use: --limit @/home/jgli/github/testing/3bed/config/walrus.retry

PLAY RECAP ************************************************************************************************************************************
172.22.0.244               : ok=0    changed=0    unreachable=1    failed=0 
```

[Here](https://gist.github.com/rcgoodfellow/0d077f854129db40cdb7940bdeabd790) is a gist with verbose output on.

##### EXPECTED RESULTS
The playbook to execute on the host, because ansible-playbook is using the key I specified in the --ssh-extra-args.

##### ACTUAL RESULTS
ansible-playbook gets rejected because it does not appear to be using the right key



Discussion:
as a workaround the `--private-key` option works. But for backwards compatibility it would be very nice if the ssh argument passing continues to work.
Probably related to this:
`ansible --ssh-extra-args='-o StrictHostKeyChecking=no'` is breaking for me in 2.4. It works fine if set the `host_key_checking` flag to False manually
Yes this seems like a regression to me too, not working here passing additional -o flags

Resolving patch:
diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py
--- a/lib/ansible/playbook/play_context.py
+++ b/lib/ansible/playbook/play_context.py
@@ -174,6 +174,9 @@
     'ansible_ssh_executable',
 )
 
+OPTION_FLAGS = ('connection', 'remote_user', 'private_key_file', 'verbosity', 'force_handlers', 'step', 'start_at_task', 'diff',
+                'ssh_common_args', 'docker_extra_args', 'sftp_extra_args', 'scp_extra_args', 'ssh_extra_args')
+
 
 class PlayContext(Base):
 
@@ -326,9 +329,8 @@ def set_options(self, options):
         self.diff = boolean(options.diff, strict=False)
 
         #  general flags (should we move out?)
-        # for flag in ('connection', 'remote_user', 'private_key_file', 'verbosity', 'force_handlers', 'step', 'start_at_task', 'diff'):
         #  should only be 'non plugin' flags
-        for flag in ('connection', 'remote_user', 'private_key_file', 'verbosity', 'force_handlers', 'step', 'start_at_task', 'diff'):
+        for flag in OPTION_FLAGS:
             attribute = getattr(options, flag, False)
             if attribute:
                 setattr(self, flag, attribute)


Test patch: