# how can I override the ansible.cfg with command line argument

**URL:** <https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002>\
**Category:** Ansible Project\
**Created:** [November 26, 2013, 3:20am UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002 "2013-11-26T03:20:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiangjun](https://avatars.discourse-cdn.com/v4/letter/x/a9a28c/32.png) [@xiangjun](https://forum.ansible.com/u/xiangjun)\
**Post date:** [November 26, 2013, 3:20am UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002/1 "2013-11-26T03:20:36Z")

</div>

I have servers with different ssh ports, the default port is configured in ansible.cfg, how can I override the remote\_port setting with command line argument? thanks

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [November 26, 2013, 4:17pm UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002/2 "2013-11-26T16:17:14Z")

</div>

Hi,

try ansible\_ssh\_port: [http://www.ansibleworks.com/docs/faq.html#id2](http://www.ansibleworks.com/docs/faq.html#id2)

---

<div class="post-metadata">

**Author:** ![xiangjun](https://avatars.discourse-cdn.com/v4/letter/x/a9a28c/32.png) [@xiangjun](https://forum.ansible.com/u/xiangjun)\
**Post date:** [November 27, 2013, 1:25am UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002/3 "2013-11-27T01:25:21Z")

</div>

My inventory file is big, I want to keep it clean, changing every line is not so good.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 27, 2013, 3:13am UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002/4 "2013-11-27T03:13:42Z")

</div>

Add it to a group then.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 27, 2013, 3:11pm UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002/5 "2013-11-27T15:11:08Z")

</div>

you can also use extra vars: -e ‘ansible\_ssh\_port=2343’

---

<div class="post-metadata">

**Author:** ![xiangjun](https://avatars.discourse-cdn.com/v4/letter/x/a9a28c/32.png) [@xiangjun](https://forum.ansible.com/u/xiangjun)\
**Post date:** [November 28, 2013, 2:12am UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002/6 "2013-11-28T02:12:47Z")

</div>

to Michael,  
I known add it to the group, but it is not best practice.

to Brian,  
do you mean add -e in command line? I got an error that:

ansible -i xcloud all -a ‘w’ -e ‘ansible\_ssh\_port=22’  
Usage: ansible [options]

ansible: error: no such option: -e

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 28, 2013, 3:34am UTC](https://forum.ansible.com/t/how-can-i-override-the-ansible-cfg-with-command-line-argument/14002/7 "2013-11-28T03:34:07Z")

</div>

-e is for ansible-playbook, sorry, i didn’t realize you were using the oneliner
