ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
198 stars 153 forks source link

win_lineinfile: Unable to edit files in AFS mount path #507

Open parthadas-1986 opened 1 year ago

parthadas-1986 commented 1 year ago
SUMMARY

The Azure File Share is successfully mounted on the Windows VM (Windows Server 2019 Datacenter), and required permissions are added as per Microsoft document. But whenever we are trying to update any file with in the share path using ansible code(win_lineinfile), we are getting "File path does not exists" error. But in the same VM, we are able to edit file in other physical location and also we can manually update file in AFS path, only via ansible it is not working. Please note, We are running the ansible code from Control node (i.e. A Linux vm in same vnet and same region)

ISSUE TYPE
COMPONENT NAME

win_lineinfile

ANSIBLE VERSION
ansible [core 2.11.12] 
  config file = None
  configured module search path = ['/home/admin_accenture/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  ansible collection location = /home/admin_accenture/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.6.15 (default, Sep 23 2021, 15:41:43) [GCC]
  jinja version = 2.10.1
  libyaml = False
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT

Windows 2019 Datacenter

STEPS TO REPRODUCE
---

- name: windows mssql install
  hosts: mssql  
  gather_facts: yes  
  tasks:    
    - name: Edit Default.PFL file(Profile Edit)
      win_lineinfile:
        #path: \saptest12.file.core.windows.net\sapmnt\TEST\DEFAULT.PFL.txt
        path: Y:\TEST\DEFAULT.PFL.txt        
        regex: "{{ item.from }}"
        line: "{{ item.to }}"
        remote_src: true
      with_items: 
        - { from: '^SAPDBHOST ='  , to: 'SAPDBHOST = windows' } 
EXPECTED RESULTS

"SAPDBHOST =" text should replaced with 'SAPDBHOST = windows' in the file located in AFS mount path

ACTUAL RESULTS

File is not getting updated after running this playbook.

jborean93 commented 1 year ago

Mapped drives are not created on network logons so they won’t be accessible in Ansible tasks. You’ll have to use the UNC path to the Azure File Share and also use become to unlock the credential manager store or specify explicit credentials for authentication.

parthadas-1986 commented 1 year ago

Mapped drives are not created on network logons so they won’t be accessible in Ansible tasks. You’ll have to use the UNC path to the Azure File Share and also use become to unlock the credential manager store or specify explicit credentials for authentication.

Thanks for your reply, I already tried with UNC path also, getting same result, But i have to check with become option, that i haven't tried yet.

jborean93 commented 1 year ago

UNC will allow it to connect but you need something to overcome the double hop/credential delegation problem. Become is one way of doing so.

parthadas-1986 commented 1 year ago

Hi, I have tried with following playbook

- name: windows mssql install
  hosts: mssql  
  gather_facts: yes    
  become_user: ansibleusr
  tasks:    
    - name: Edit Default.PFL file(Profile Edit)
      win_lineinfile:
        path: \saptest16.file.core.windows.net\sapmnt\TEST\DEFAULT.PFL               
        regex: "{{ item.from }}"
        line: "{{ item.to }}"
        remote_src: true
      with_items: 
        - { from: '^SAPDBHOST ='  , to: 'SAPDBHOST = windows' } 

But still getting following error

TASK [Edit Default.PFL file(Profile Edit)] **** Wednesday 12 April 2023 07:12:21 +0000 (0:00:06.414) 0:00:06.611 *** failed: [sqltest01.azsqlha.cloudcoe.local] (item={'from': '^SAPDBHOST =', 'to': 'SAPDBHOST = windows'}) => {"ansible_loop_var": "item", "changed": false, "item": {"from": "^SAPDBHOST =", "to": "SAPDBHOST = windows"}, "msg": "Path \saptest16.file.core.windows.net\sapmnt\TEST\DEFAULT.PFL does not exist !"}