From 4157d7a5df083a49bfb3b1d1c7cd5f233c1930c4 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Thu, 5 Sep 2019 16:49:15 -0400 Subject: [PATCH] Use blockinfile for tripleo-ssh-known-hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lineinfile combined with with_items was very inefficient for this task. Given that each node's hostkey is added to every other host, it resulted in O(n²) performance. Additional networks per node also worsened the problem. For example, in a 100 node deployment, with 4 networks per node, this task would need to be executed 40,000 times (100 * 100 * 4). Switching to use blockinfile brings the performance back to O(n), and also removes any dependency on the number of networks per node. Change-Id: Id51d27f53abf3421c29a11065377e9303ad68d79 --- tripleo_ansible/roles/tripleo-ssh-known-hosts/tasks/main.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tripleo_ansible/roles/tripleo-ssh-known-hosts/tasks/main.yml b/tripleo_ansible/roles/tripleo-ssh-known-hosts/tasks/main.yml index 927e31fe6..27c6713e5 100644 --- a/tripleo_ansible/roles/tripleo-ssh-known-hosts/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo-ssh-known-hosts/tasks/main.yml @@ -61,11 +61,10 @@ {% endfor %} - name: Add host keys to temporary ssh_known_hosts - lineinfile: + blockinfile: path: "{{ ssh_known_hosts_tmp.path }}" - line: "{{ item }}" + block: "{{ ssh_known_hosts_lines }}" create: true - with_items: "{{ ssh_known_hosts_lines.splitlines() }}" # Workaround https://bugs.launchpad.net/tripleo/+bug/1810932 # Ansible modules perform a replace instead of in-place modification.