Repository: freedomofpress/securedrop

Issue:
Remove unnecessary Ansible callback for profile_tasks
# Feature request

## Description

The file at `install_files/ansible-base/callback_plugins/profile_tasks.py` was added via #1196, to provide additional information on task performance, with the goal of aiding developers in improving the server config workflow. Since we moved to Ansible v2 in #1146, the hardcoded plugin is no longer necessary.

Instead, we can ansible add a lint to `ansible.cfg` under `[defaults]`:

```
callback_whitelist = profile_tasks
```

The simplification is possible because task profiling was [added to Ansible core as of v2](https://docs.ansible.com/ansible/devel/plugins/callback/profile_tasks.html).

## User Stories
As a maintainer, I want to delete redundant code wherever possible, and lean on upstream to handle core functionality when appropriate.



Discussion:

Resolving patch:
diff --git a/install_files/ansible-base/callback_plugins/profile_tasks.py b/install_files/ansible-base/callback_plugins/profile_tasks.py
deleted file mode 100644
--- a/install_files/ansible-base/callback_plugins/profile_tasks.py
+++ /dev/null
@@ -1,74 +0,0 @@
-# Source: https://github.com/jlafon/ansible-profile
-# License: MIT
-# More info: http://jlafon.io/ansible-profiling.html
-# The profiling functionality will be provided by Ansible v2,
-# since this callback_plugin has been merged into core,
-# but we're including here to support older versions of Ansible.
-import datetime
-import os
-import time
-
-
-class CallbackModule(object):
-    """
-    A plugin for timing tasks
-    """
-    def __init__(self):
-        self.stats = {}
-        self.current = None
-
-    def playbook_on_task_start(self, name, is_conditional):
-        """
-        Logs the start of each task
-        """
-
-        if os.getenv("ANSIBLE_PROFILE_DISABLE") is not None:
-            return
-
-        if self.current is not None:
-            # Record the running time of the last executed task
-            self.stats[self.current] = time.time() - self.stats[self.current]
-
-        # Record the start time of the current task
-        self.current = name
-        self.stats[self.current] = time.time()
-
-    def playbook_on_stats(self, stats):
-        """
-        Prints the timings
-        """
-
-        if os.getenv("ANSIBLE_PROFILE_DISABLE") is not None:
-            return
-
-        # Record the timing of the very last task
-        if self.current is not None:
-            self.stats[self.current] = time.time() - self.stats[self.current]
-
-        # Sort the tasks by their running time
-        results = sorted(
-            self.stats.items(),
-            key=lambda value: value[1],
-            reverse=True,
-        )
-
-        # Just keep the top 10
-        results = results[:10]
-
-        # Print the timings
-        for name, elapsed in results:
-            print(
-                "{0:-<70}{1:->9}".format(
-                    '{0} '.format(name),
-                    ' {0:.02f}s'.format(elapsed),
-                )
-            )
-
-        total_seconds = sum([x[1] for x in self.stats.items()])
-        print("\nPlaybook finished: {0}, {1} total tasks."
-              " {2} elapsed. \n".format(
-                time.asctime(),
-                len(self.stats.items()),
-                datetime.timedelta(seconds=(int(total_seconds)))
-                )
-              )


Test patch: