File: //lib/python3.9/site-packages/ansible/plugins/callback/__pycache__/tree.cpython-39.pyc
a
�)g� � @ sp d dl mZmZmZ eZdZd dlZd dlm Z d dl
mZmZ d dl
mZ d dlmZmZ G dd � d e�ZdS )
� )�absolute_import�division�print_functionaB
name: tree
type: notification
requirements:
- invoked in the command line
short_description: Save host events to files
version_added: "2.0"
options:
directory:
version_added: '2.11'
description: directory that will contain the per host JSON files. Also set by the C(--tree) option when using adhoc.
ini:
- section: callback_tree
key: directory
env:
- name: ANSIBLE_CALLBACK_TREE_DIR
default: "~/.ansible/tree"
type: path
description:
- "This callback is used by the Ansible (adhoc) command line option C(-t|--tree)."
- This produces a JSON dump of events in a directory, a file for each host, the directory used MUST be passed as a command line option.
N)�TREE_DIR)�to_bytes�to_text)�CallbackBase)�
makedirs_safe�unfrackpathc s\ e Zd ZdZdZdZdZdZd� fdd� Zd d
� Z dd� Z
d
d� Zddd�Zdd� Z
� ZS )�CallbackModulez]
This callback puts results into a host specific file in a directory in json format.
g @Z aggregate�treeTNc s6 t t| �j|||d� tr&tt�| _n| �d�| _dS )z override to set self.tree )� task_keys�var_options�directZ directoryN)�superr �set_optionsr r
r Z
get_option)�selfr
r r �� __class__� �A/usr/lib/python3.9/site-packages/ansible/plugins/callback/tree.pyr 1 s zCallbackModule.set_optionsc
C s� t |�}zt| j� W nF ttfy\ } z*| j�dt| j�t|�f � W Y d}~n
d}~0 0 zLt tj �
| j|��}t|d��}|�|� W d � n1 s�0 Y W n@ ttfy� } z$| j�d|t|�f � W Y d}~n
d}~0 0 dS )z' write something into treedir/hostname z<Unable to access or create the configured directory (%s): %sNzwb+z Unable to write to %s's file: %s)
r r r �OSError�IOErrorZ_displayZwarningr �os�path�join�open�write)r �hostname�buf�er �fdr r r �write_tree_file<