Vi2016-04-07 17:00:57
System administration
Vi, 2016-04-07 17:00:57

Ansible change ssh port without changing inventory file?

In general, how to change the port of the ssh server using ansible-playbook so that you do not change the configuration file later?
otherwise if I run ansible so that it changes the port on the server, then I then have to change the connection port itself in the file

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Konkase, 2016-04-07

- local_action: lineinfile dest={{ inventory_file }} regexp='^{{ inventory_hostname }}.*' line='{{ inventory_hostname }} ansible_ssh_port={{ new_port }}' state=present

Pavel Selivanov, 2016-04-07

If the ssh port changes on the server, then it must be changed in the configuration file, otherwise this file will become inoperable. It is possible, as Konkase suggested , to edit the file automatically from the same ansible. You can use dynamic inventory and get data about servers, groups and their parameters, including the port, from somewhere in the database / api of the cloud provider, etc. But even in this case, you will have to change this value in this database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question