AWX fails to retrieve collections from Ansible Galaxy - ansible

I have a project with roles/requirements.yml and collections/requirements.yml. This - I think - per AWX / Tower guidelines.
On project update the roles/requirements.yml is picked up successfully but the collections/requirements.yml fails with a typical Ansible error message unfortunately that doesn't help me understand what is going wrong.
PLAY [Update source tree if necessary] *****************************************
TASK [delete project directory before update] **********************************
changed: [localhost]
TASK [update project using git] ************************************************
changed: [localhost]
TASK [Set the git repository version] ******************************************
ok: [localhost]
TASK [Repository Version] ******************************************************
ok: [localhost] => {
"msg": "Repository Version 812a488b0a09f7fda6a784a8247abaf6892e1f13"
}
PLAY [Install content with ansible-galaxy command if necessary] ****************
TASK [detect roles/requirements.(yml/yaml)] ************************************
ok: [localhost] => (item={'ext': '.yml'})
ok: [localhost] => (item={'ext': '.yaml'})
TASK [fetch galaxy roles from requirements.(yml/yaml)] *************************
changed: [localhost] => (item={'changed': False, 'stat': {'exists': True, 'path': '/var/lib/awx/projects/_6__c2/roles/requirements.yml', 'mode': '0644', 'isdir': False, 'ischr': False, 'isblk': False, 'isreg': True, 'isfifo': False, 'islnk': False, 'issock': False, 'uid': 0, 'gid': 0, 'size': 390, 'inode': 131356, 'dev': 64771, 'nlink': 1, 'atime': 1613038457.4215767, 'mtime': 1613038456.678576, 'ctime': 1613038456.678576, 'wusr': True, 'rusr': True, 'xusr': False, 'wgrp': False, 'rgrp': True, 'xgrp': False, 'woth': False, 'roth': True, 'xoth': False, 'isuid': False, 'isgid': False, 'blocks': 8, 'block_size': 4096, 'device_type': 0, 'readable': True, 'writeable': True, 'executable': False, 'pw_name': 'root', 'gr_name': 'root', 'checksum': '29ae537db56b12b54f2eecb8668f4185b7b1e91d', 'mimetype': 'text/plain', 'charset': 'us-ascii', 'version': None, 'attributes': [], 'attr_flags': ''}, 'invocation': {'module_args': {'path': '/var/lib/awx/projects/_6__c2/roles/requirements.yml', 'follow': False, 'get_md5'…
skipping: [localhost] => (item={'changed': False, 'stat': {'exists': False}, 'invocation': {'module_args': {'path': '/var/lib/awx/projects/_6__c2/roles/requirements.yaml', 'follow': False, 'get_md5': False, 'get_checksum': True, 'get_mime': True, 'get_attributes': True, 'checksum_algorithm': 'sha1'}}, 'failed': False, 'item': {'ext': '.yaml'}, 'ansible_loop_var': 'item'})
TASK [detect collections/requirements.(yml/yaml)] ******************************
ok: [localhost] => (item={'ext': '.yml'})
ok: [localhost] => (item={'ext': '.yaml'})
TASK [fetch galaxy collections from collections/requirements.(yml/yaml)] *******
failed: [localhost] (item={'changed': False, 'stat': {'exists': True, 'path': '/var/lib/awx/projects/_6__c2/collections/requirements.yml', 'mode': '0644', 'isdir': False, 'ischr': False, 'isblk': False, 'isreg': True, 'isfifo': False, 'islnk': False, 'issock': False, 'uid': 0, 'gid': 0, 'size': 183, 'inode': 131286, 'dev': 64771, 'nlink': 1, 'atime': 1613038457.4195766, 'mtime': 1613038456.673576, 'ctime': 1613038456.673576, 'wusr': True, 'rusr': True, 'xusr': False, 'wgrp': False, 'rgrp': True, 'xgrp': False, 'woth': False, 'roth': True, 'xoth': False, 'isuid': False, 'isgid': False, 'blocks': 8, 'block_size': 4096, 'device_type': 0, 'readable': True, 'writeable': True, 'executable': False, 'pw_name': 'root', 'gr_name': 'root', 'checksum': '7b8e2a2b64c7d5e64917b548dc40347158f8bb1b', 'mimetype': 'text/plain', 'charset': 'us-ascii', 'version': None, 'attributes': [], 'attr_flags': ''}, 'invocation': {'module_args': {'path': '/var/lib/awx/projects/_6__c2/collections/requirements.yml', 'follow': False, '…
skipping: [localhost] => (item={'changed': False, 'stat': {'exists': False}, 'invocation': {'module_args': {'path': '/var/lib/awx/projects/_6__c2/collections/requirements.yaml', 'follow': False, 'get_md5': False, 'get_checksum': True, 'get_mime': True, 'get_attributes': True, 'checksum_algorithm': 'sha1'}}, 'failed': False, 'item': {'ext': '.yaml'}, 'ansible_loop_var': 'item'})
Of course I tested the requirements locally. It works. Just not in AWX.
With the exception of one task having status failed I really don't see any difference between the error message on failure and the success logging when fetches roles.
What is wrong here?

I just came across this question since I encountered the same situation. I was able to resolve my issue and would like to share my approach. My AWX version is 17.1.0 (Docker image).
How to identify the root cause
enable the -vvv option as sadok-f suggested (see detailed instructions below)
open the job execution logs
click on the logline of the failing task (a small pop-up appears)
click the JSON tab (or Standard Error - Most details are provided in the JSON tab)
read the significantly more descriptive error message
My issue was, that I had a typo in the Ansible Galaxy credentials. Therefore my dependencies within the requirements.yml were not installable.
How to increase the verbosity for project jobs
As mentioned by sadok-f, enable the -vvv option for more verbosity. That option is a bit hidden. You can see the current configuration at Settings > Jobs settings. Now look for "Run Project Updates With Higher Verbosity" (the project update triggers the installation of requirements.yml files).
At least for AWX 17.1.0, editing the settings via the GUI is not implemented. You need to patch the settings via AWX-API to enable the project update-job verbosity. To do so, visit the AWX-API:
<your-awx-fqdn>/api/v2/settings/jobs/
At the bottom of the page, you have a small window that allows you to modify the content. Within the content box look for:
"PROJECT_UPDATE_VVV": false,
and change it to:
"PROJECT_UPDATE_VVV": true,
Click the PATCH button. That enables the -vvv option for project refresh jobs. As written, those refresh jobs install the requirements.
Synch your project and have a look at the significantly more verbose job logs (Projects > Sync Project (the tiny cycle-arrow button)).

Related

ansible with_sequence result message hide

I want to hide the result message of with_sequence:
My task playbook :
- name: Alarm check
debug: msg="Alarm check"
when: '"{{ item }} alarms currently active" in HOST_MGMT1.stdout'
register: result_alarm
with_sequence: start=0 end=10
result output message:
##########_QFX10K_##########
Current time: 2020-03-13 11:34:58 KST
{All items completed', 'changed': False, 'results': [{'item': u'0', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'1', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'2', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {Alarm check', 'item': u'3', 'ansible_loop_var': u'item', 'changed': False, 'failed': False}, {'item': u'4', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'5', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'6', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'7', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'8', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'9', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}, {'item': u'10', 'skipped': True, 'ansible_loop_var': u'item', 'changed': False, 'skip_reason': u'Conditional result was False'}]}
Try skippy callback plugin. For example the playbook
shell> cat playbook.yml
- hosts: localhost
vars:
HOST_MGMT1:
stdout: "3 alarms currently active"
tasks:
- name: Alarm check
debug: msg="Alarm check"
when: "my_item in HOST_MGMT1.stdout"
register: result_alarm
with_sequence: start=0 end=10
vars:
my_item: "{{ item }} alarms currently active"
gives (abbridged)
shell> export ANSIBLE_STDOUT_CALLBACK=skippy
shell> ansible-playbook playbook.yml
PLAY [localhost] ***
TASK [Alarm check] ***
ok: [localhost] => (item=3) => {
"msg": "Alarm check"
}
PLAY RECAP ***
localhost: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

ansible output multiple variables to same line

I'm collecting the SQL version and edition found in registry using win_reg_stat, registering these into a variable, and writing them to a file.
Is it possible to write the values to the same line instead of separate lines?
- name: get sql version
win_reg_stat:
path: HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{{ item }}\Setup
name: Version
with_items: "{{ sql_versions }}"
register: sql_version
- name: get sql edition
win_reg_stat:
path: HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{{ item }}\Setup
name: Edition
with_items: "{{ sql_versions }}"
register: sql_edition
- lineinfile:
dest: /tmp/sql
line: "{{ inventory_hostname }};{{ item.value }}"
when: item.exists
with_items:
- "{{ sql_version.results }}"
delegate_to: localhost
- lineinfile:
dest: /tmp/sql
line: "{{ inventory_hostname }};{{ item.value }}"
when: item.exists
with_items:
- "{{ sql_edition.results }}"
delegate_to: localhost
The sql_versions variable contains multiple items:
sql_versions:
- MSSQL15.MSSQLSERVER
- MSSQL14.MSSQLSERVER
- MSSQL13.MSSQLSERVER
- MSSQL12.MSSQLSERVER
- MSSQL11.MSSQLSERVER
- MSSQL10_50.MSSQLSERVER
- MSSQL10.MSSQLSERVER
- MSSQL.1
Output example:
TASK [licensing : register sql version] *****************************************************************************************************************************************************************************************************
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL15.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL14.MSSQLSERVER', 'ansible_loop_var': 'item'})
ok: [win2019] => (item={'changed': False, 'type': 'REG_SZ', 'raw_value': '13.2.5026.0', 'value': '13.2.5026.0', 'exists': True, 'failed': False, 'item': 'MSSQL13.MSSQLSERVER', 'ansible_loop_var': 'item'}) => {
"msg": "13.2.5026.0"
}
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL12.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL11.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL10_50.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL10.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL.1', 'ansible_loop_var': 'item'})
TASK [licensing : register sql edition] *****************************************************************************************************************************************************************************************************
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL15.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL14.MSSQLSERVER', 'ansible_loop_var': 'item'})
ok: [win2019] => (item={'changed': False, 'type': 'REG_SZ', 'raw_value': 'Web Edition', 'value': 'Web Edition', 'exists': True, 'failed': False, 'item': 'MSSQL13.MSSQLSERVER', 'ansible_loop_var': 'item'}) => {
"msg": "Web Edition"
}
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL12.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL11.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL10_50.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL10.MSSQLSERVER', 'ansible_loop_var': 'item'})
skipping: [win2019] => (item={'changed': False, 'exists': False, 'failed': False, 'item': 'MSSQL.1', 'ansible_loop_var': 'item'})
did you tried this..
- lineinfile:
dest: /tmp/sql
line: "{{ inventory_hostname }};{{ item.value }}"
when: item.exists
with_items:
- "{{ sql_version.results }}"
- "{{ sql_edition.results }}"
delegate_to: localhost
Please try as below (not tested)
- lineinfile:
dest: /tmp/sql
line: "{{ inventory_hostname }};{{ item.version.value }};{{ item.edition.value }}"
when: item.exists
with_items:
- "{ version: {{sql_version.results}}, edition: {{sql_edition.results}} }"
delegate_to: localhost

How to resolve the dependencies for locally downloaded packages in Ansible? When package A is depends on Package B

I have simple playbook where trying to install the Debian packages downloaded locally in my server. This playbook runs on localhost and install the Debian packages in the same system. But this playbook gives an error "Dependency is not satisfiable for some of the packages even tough the dependency package is available in the local repository.
I can download all the dependencies required for the specific package in my local repository using apt-get install --download-only package_name
But in my playbook, i should have a mechanism to install the dependencies first than install the actual package. This task should be dynamic, playbook should resolve the dependencies by itself for any package install.
When the package has dependency over another package, How the playbook resolve dynamically.
Some of the options explored:
Using ordered indexed_items, using gdebi.. Looking for efficient Logic.
Local Repository has packages -> It can grow depends on the requirement:
wireshark_3.0.5-1_amd64.deb wireshark-qt_3.0.5-1_amd64.deb
Here wireshark_3.0.5-1_amd64.deb has dependency over wireshark-qt_3.0.5-1_amd64.deb.
install_dependencies.yml
---
- hosts: localhost
vars:
remote_media_directory: "/home/local_repository"
become: yes
tasks:
- name: find all debian Packages
find:
paths:
- "{{ remote_media_directory }}"
file_type: file
recurse: yes
use_regex: yes
patterns:
- '.*deb$'
register: files_matched_subdirectory
- name: installation debian packages
apt:
deb: "{{ item.path }}"
with_items: "{{ files_matched_subdirectory.files }}"
when: ansible_distribution == "Ubuntu"
ansible-playbook install_dependencies.yml
PLAY [localhost] **********************************************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
ok: [localhost]
TASK [find all debian Packages] *******************************************************************************************************************************************************************************
ok: [localhost]
TASK [installation debian packages] ***************************************************************************************************************************************************************************
failed: [localhost] (item={u'uid': 0, u'woth': False, u'mtime': 1571850269.5720358, u'inode': 31195175, u'isgid': False, u'size': 46700, u'roth': True, u'isuid': False, u'isreg': True, u'pw_name': u'root', u'gid': 0, u'ischr': False, u'wusr': True, u'xoth': False, u'rusr': True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr_name': u'root', u'path': u'/home/local_repository/wireshark_3.0.5-1_amd64.deb', u'xusr': False, u'atime': 1571850391.3553286, u'isdir': False, u'ctime': 1571850312.2437878, u'wgrp': False, u'xgrp': False, u'dev': 2051, u'isblk': False, u'isfifo': False, u'mode': u'0644', u'islnk': False}) => {"changed": false, "item": {"atime": 1571850391.3553286, "ctime": 1571850312.2437878, "dev": 2051, "gid": 0, "gr_name": "root", "inode": 31195175, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1571850269.5720358, "nlink": 1, "path": "/home/local_repository/wireshark_3.0.5-1_amd64.deb", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 46700, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, "msg": "Dependency is not satisfiable: wireshark-qt (= 3.0.5-1)\n"}
failed: [localhost] (item={u'uid': 0, u'woth': False, u'mtime': 1571850269.4560366, u'inode': 31195174, u'isgid': False, u'size': 3605060, u'roth': True, u'isuid': False, u'isreg': True, u'pw_name': u'root', u'gid': 0, u'ischr': False, u'wusr': True, u'xoth': False, u'rusr': True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr_name': u'root', u'path': u'/home/local_repository/wireshark-qt_3.0.5-1_amd64.deb', u'xusr': False, u'atime': 1571850394.3993108, u'isdir': False, u'ctime': 1571850312.2437878, u'wgrp': False, u'xgrp': False, u'dev': 2051, u'isblk': False, u'isfifo': False, u'mode': u'0644', u'islnk': False}) => {"changed": false, "item": {"atime": 1571850394.3993108, "ctime": 1571850312.2437878, "dev": 2051, "gid": 0, "gr_name": "root", "inode": 31195174, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1571850269.4560366, "nlink": 1, "path": "/home/local_repository/wireshark-qt_3.0.5-1_amd64.deb", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 3605060, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, "msg": "Dependency is not satisfiable: libc6 (>= 2.29)\n"}
ok: [localhost] => (item={u'uid': 0, u'woth': False, u'mtime': 1571850217.1323407, u'inode': 31195169, u'isgid': False, u'size': 40654, u'roth': True, u'isuid': False, u'isreg': True, u'pw_name': u'root', u'gid': 0, u'ischr': False, u'wusr': True, u'xoth': False, u'rusr': True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr_name': u'root', u'path': u'/home/local_repository/tree_1.7.0-5_amd64.deb', u'xusr': False, u'atime': 1571850397.4392931, u'isdir': False, u'ctime': 1571850312.2437878, u'wgrp': False, u'xgrp': False, u'dev': 2051, u'isblk': False, u'isfifo': False, u'mode': u'0644', u'islnk': False})
ok: [localhost] => (item={u'uid': 0, u'woth': False, u'mtime': 1571850217.0163412, u'inode': 31195168, u'isgid': False, u'size': 52132, u'roth': True, u'isuid': False, u'isreg': True, u'pw_name': u'root', u'gid': 0, u'ischr': False, u'wusr': True, u'xoth': False, u'rusr': True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr_name': u'root', u'path': u'/home/local_repository/dstat_0.7.3-1_all.deb', u'xusr': False, u'atime': 1571850399.3192823, u'isdir': False, u'ctime': 1571850312.2437878, u'wgrp': False, u'xgrp': False, u'dev': 2051, u'isblk': False, u'isfifo': False, u'mode': u'0644', u'islnk': False})
to retry, use: --limit #/home/upgrade/ansible/install_dependencies.retry
PLAY RECAP ****************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=1
First Setup local repository in the remote server and download install packages using apt-get install --download-only package_name in the remote server. Modify local system /etc/apt/sources.list to point to the local repository packages.
When ansible script try to install using apt-get -y install , it will connect to the local repository and fetches the packages and resolves the dependencies.
Please check the below links for more info
https://kerneltalks.com/package/how-to-configure-local-apt-repository/
https://askubuntu.com/questions/170348/how-to-create-a-local-apt-repository

How to grab filepath from ansibles find module

I'm using Ansible for some IAC(infra as code) tasks.
I have a playbook where I'm using the find module recursively to search for readable files.
Here is an example of it:
- name: Application logs with read access
become: true
find:
paths: /
file_type: file
recurse: yes
patterns:
- '*.log'
- '*.config'
register: rapplogs
- set_fact: read_app_logs={{rapplogs.matched}}
- debug: var=read_app_logs
- set_fact: read_log_list={{rapplogs.files}}
- debug: var=read_log_list
run_once: True
failed_when: read_app_logs >= 1
ignore_errors: True
The output of it is like this:
TASK [infra_pt : set_fact] ******************************************************************
ok: [192.168.47.135]
TASK [infra_pt : debug] *********************************************************************
ok: [192.168.47.135] => {
"read_app_logs": "72"
}
TASK [infra_pt : set_fact] ******************************************************************
ok: [192.168.47.135]
TASK [infra_pt : debug] *********************************************************************
fatal: [192.168.47.135]: FAILED! => {
"failed_when_result": true,
"read_log_list": {
"changed": false,
"examined": 210060,
"failed": false,
"files": [
{
"atime": 1558446815.3474104,
"ctime": 1558446815.3474104,
"dev": 64768,
"gid": 0,
"gr_name": "root",
"inode": 2065610,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1558446815.3474104,
"nlink": 1,
"path": "/test2.log",
"pw_name": "root",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 0,
"uid": 0,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
},
From the output list I actually want to access only the "mode" and "path" objects, how this can be done? Any idea?
Try json_query
- set_fact:
read_app_logs: "{{ rapplogs.files|json_query('[].{path: path, mode: mode}') }}"
(not tested)
Sure. You can just iterate over the list of matched files and refer to whichever keys are of interest:
- debug:
msg: "mode of {{ item.path }} is {{ item.mode }}"
loop: "{{ read_log_list.files }}"
Which, given your example output, would produce something like this:
TASK [debug] **********************************************************************************
ok: [localhost] => (item={u'islnk': False, u'uid': 0, u'rgrp': True, u'xoth': False, u'rusr': True, u'woth': False, u'nlink': 1, u'issock': False, u'mtime': 1558446815.3474104, u'gr_name': u'root', u'path': u'/test2.log', u'xusr': False, u'atime': 1558446815.3474104, u'inode': 2065610, u'isgid': False, u'size': 0, u'isdir': False, u'wgrp': False, u'ctime': 1558446815.3474104, u'isblk': False, u'xgrp': False, u'isuid': False, u'dev': 64768, u'roth': True, u'isreg': True, u'isfifo': False, u'mode': u'0644', u'pw_name': u'root', u'gid': 0, u'ischr': False, u'wusr': True}) => {
"msg": "mode of /test2.log is 0644"
}

Need to find conf file on the system and need to replace a line

Everyone, I am using the below script to find all the httpd.conf file in /tmp using the find module and after that, i need to change the server root for all the httpd.conf files that I got from the find module. I am using the Below code.
getting the below error while executing the lineinline module.
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Destination {'files': [{'uid': 0, 'woth': False, 'mtime': 1554392266.9903164, 'inode': 4232796, 'isgid': False, 'size': 11753, 'roth': True, 'isuid': False, 'isreg': True, 'pw_name': 'root', 'gid': 0, 'ischr': False, 'wusr': True, 'xoth': False, 'rusr': True, 'nlink': 1, 'issock': False, 'rgrp': True, 'gr_name': 'root', 'path': '/tmp/httpd.conf', 'xusr': False, 'atime': 1554391744.8432574, 'isdir': False, 'ctime': 1554392266.9903164, 'wgrp': False, 'xgrp': False, 'dev': 51714, 'isblk': False, 'isfifo': False, 'mode': '0644', 'islnk': False}], 'changed': False, 'failed': False, 'examined': 14, 'msg': '', 'matched': 1} does not exist !", "rc": 257}
to retry, use: --limit #/etc/ansible/findnew.retry
---
- name: Recursively find httpd.conf file in /tmp
connection: local
hosts: localhost
tasks:
- find:
paths: /tmp
patterns: '*.conf'
recurse: yes
register: filestoser
- debug: var=filestoser
- lineinfile:
path: '{{ filestoser }}'
state: present
regexp: '^ServerRoot'
line: 'ServerRoot_new'
Your problem is that you're trying to use the variable filestoser as a filename, but it's not: it's the result of the find task. If you take a look at the output of your debug task you'll see something like this:
TASK [debug] **********************************************************************************
ok: [localhost] => {
"filestoser": {
"changed": false,
"examined": 44,
"failed": false,
"files": [
{
"atime": 1554394659.885133,
"ctime": 1554394659.885133,
"dev": 45,
"gid": 21937,
"gr_name": "lars",
"inode": 172846,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1554394659.885133,
"nlink": 1,
"path": "/tmp/etc/httpd/httpd.conf",
"pw_name": "lars",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 11753,
"uid": 21937,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
}
],
"matched": 1,
"msg": ""
}
}
In other words, filestoser is a dictionary. The files key contains a list of files that were matched by the files task. You could rewrite your lineinfile task like this, if you want to operate on the first file found:
- lineinfile:
path: '{{ filestoser.files.0.path }}'
state: present
regexp: '^ServerRoot'
line: 'ServerRoot_new'

Resources