{"id":25638,"date":"2023-06-06T14:26:56","date_gmt":"2023-06-06T12:26:56","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=25638"},"modified":"2025-01-24T10:42:36","modified_gmt":"2025-01-24T09:42:36","slug":"awx-log-keeper","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/","title":{"rendered":"AWX log keeper."},"content":{"rendered":"\n<p>by Alexandre Nestor<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-scope\">Scope<\/h2>\n\n\n\n<p>The aim of this project is to use Ansible  role to export AWX Tower logs on disk.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-introduction\">Introduction<\/h2>\n\n\n\n<p>Accessing log files isn&#8217;t always easy. Searching for errors across multiple log files, for workflows for example, or nested playbooks can be a difficult task.<br>The proposed role extracts logs between two dates, or between two id executions, and saves them to disk.<br>The role saves in parallel with the ansible execution log, the json file with each job&#8217;s description, name, parameters and all execution-related information.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-download\">Download<\/h2>\n\n\n\n<p>The role is freely distributed from Github: <a href=\"https:\/\/github.com\/nax71\/awx_log_keeper\">https:\/\/github.com\/nax71\/awx_log_keeper<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parameters\">Parameters<\/h2>\n\n\n\n<p>The variables used are described in the <code>playbooks\/vars\/awx_logs_keeper_vars.yml<\/code> as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n---\nlog_path_root: &quot;\/foo\/bar\/awx_logs&quot;\nawx:\n  tower_base_url: &quot;https:\/\/awx.prod.mytest.ch&quot;\n  tower_username: &quot;{{ awx_username }}&quot;\n  tower_password: &quot;{{ awx_password }}&quot;\n job_id_interval:\n   start: 2\n   end: 5\ndate_interval:\n  start: &quot;2022-10-20T10:00:00&quot;\n  end: &quot;2022-10-20T13:00:00&quot;\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><code>log_pat_root<\/code>: Is the path where the logs will be saved<\/li>\n\n\n\n<li><code>awx<\/code> section is used for awx credentials and web sevrver address<\/li>\n\n\n\n<li><code>job_id_interval<\/code><\/li>\n\n\n\n<li>instruct the playbook to get logs got all jobs from <code>job_id_interval.start<\/code> and <code>job_id_interval.end<\/code>.<\/li>\n\n\n\n<li><code>date_interval<\/code><\/li>\n\n\n\n<li>instruct the playbook to get logs got all jobs between <code>date_interval.start<\/code> date and <code>date_interval.end<\/code> date.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>date_interval.start<\/code> must be lower than <code>date_interval.end<\/code>.<\/li>\n\n\n\n<li><code>job_id_interval.start<\/code> must be lower than <code>job_id_interval.end<\/code>.<\/li>\n\n\n\n<li>Values of <code>job_id_interval<\/code> and <code>date_interval<\/code> are <strong>not<\/strong> mutual exclusive, but at least <strong>one<\/strong> of <code>date_interval<\/code> or <code>job_id-interval<\/code> must be given.<\/li>\n<\/ul>\n\n\n\n<p>The playbook will test first if <code>date_interval<\/code> make sense, then it gets all <code>job_id<\/code> between these two dates. At the end it will add the <code>job_id_interval<\/code>, and get all logs for the obtained <code>job_id<\/code> list.<\/p>\n\n\n\n<p>The output is written in <code>log_path_root\/date_of_job_execution\/job_id<\/code>. <\/p>\n\n\n\n<p>Two files are produced :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>output_&lt;job_id&gt;_&lt;DDMMYYY_HHMISS&gt;.log<\/code> is the ansible output of the log.<\/li>\n\n\n\n<li><code>&lt;job_id&gt;_&lt;DDMMYYY_HHMISS&gt;.json<\/code> is the json description of the job.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example\">Example:<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Execute the playbook by modifying the default value of log_path_root\n$&amp;gt;  ansible-playbook playbooks\/awx_logs_keeper_vars.yml -e &quot;log_path_root=\/tmp\/awx_logs&quot; --vault-password-file playbooks\/vars\/vault-pass\n\n....\nTASK &#x5B;awx_get_one_log : Out the logfile path] **********************************************************************************************************\nok: &#x5B;localhost] =&amp;gt; {\n    &quot;msg&quot;: &quot;Write Log for job id 324299 to \/tmp\/awx_logs\/20-10-2022\/324299&quot;\n}\n....\n\n$&amp;gt; cd \/tmp\/awx_logs\/20-10-2022\/324299\n$&amp;gt; ls\n324299_20102022_111602.json   output_324299_20102022_111602.log\n<\/pre><\/div>\n\n\n<p><strong>Note<\/strong>:<\/p>\n\n\n\n<p>In the example the <code>--vault-password-file playbooks\/vars\/vault-pass<\/code> is given to shaddow the Ansible Tower access credentials.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n......\ngather_facts: true\n  vars_files:\n    - vars\/secret.yml\n    - vars\/awx_logs_keeper_vars.yml\n...\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nShadowed parameters are:\n* `awx_password`\n* `awx_password`\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-final-thoughts\">Final thoughts<\/h2>\n\n\n\n<p>The log_keeper role can be scheduled on a daily basis, to give access to the previous day&#8217;s execution logs.<\/p>\n\n\n\n<p>This makes error investigation much easier, especially for complex playbooks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The aim of this project is to use Ansible role to export AWX logs on disk, on daily basis, to have an easy access for debug and investigation. <\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1321,1320],"tags":[150,2431,2894,2432,151],"type_dbi":[],"class_list":["post-25638","post","type-post","status-publish","format-standard","hentry","category-ansible","category-devops","tag-ansible","tag-ansible-tower","tag-automation-platform","tag-awx","tag-devops"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>AWX log keeper. - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AWX log keeper.\" \/>\n<meta property=\"og:description\" content=\"The aim of this project is to use Ansible role to export AWX logs on disk, on daily basis, to have an easy access for debug and investigation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-06T12:26:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-24T09:42:36+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"AWX log keeper.\",\"datePublished\":\"2023-06-06T12:26:56+00:00\",\"dateModified\":\"2025-01-24T09:42:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/\"},\"wordCount\":287,\"commentCount\":0,\"keywords\":[\"Ansible\",\"ansible tower\",\"Automation Platform\",\"awx\",\"DevOps\"],\"articleSection\":[\"Ansible\",\"DevOps\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/\",\"name\":\"AWX log keeper. - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2023-06-06T12:26:56+00:00\",\"dateModified\":\"2025-01-24T09:42:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AWX log keeper.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"AWX log keeper. - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/","og_locale":"en_US","og_type":"article","og_title":"AWX log keeper.","og_description":"The aim of this project is to use Ansible role to export AWX logs on disk, on daily basis, to have an easy access for debug and investigation.","og_url":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/","og_site_name":"dbi Blog","article_published_time":"2023-06-06T12:26:56+00:00","article_modified_time":"2025-01-24T09:42:36+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"AWX log keeper.","datePublished":"2023-06-06T12:26:56+00:00","dateModified":"2025-01-24T09:42:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/"},"wordCount":287,"commentCount":0,"keywords":["Ansible","ansible tower","Automation Platform","awx","DevOps"],"articleSection":["Ansible","DevOps"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/","url":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/","name":"AWX log keeper. - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2023-06-06T12:26:56+00:00","dateModified":"2025-01-24T09:42:36+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/awx-log-keeper\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"AWX log keeper."}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/25638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=25638"}],"version-history":[{"count":12,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/25638\/revisions"}],"predecessor-version":[{"id":36871,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/25638\/revisions\/36871"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=25638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=25638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=25638"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=25638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}