Firstly - sorry for the noob question.

I've written a Powershell script that is run from a play that returns in 
json the name of a zip file.

****Output from Powershell****

{
    "Name":  "latest-ansible v0.1.zip"
}

***playbook***
---
- hosts: all
  vars:
    filename: none
  tasks:
  - name: Install IIS Web-Server with sub features and management tools
    win_feature:
      name: Web-Server
      state: present
      include_sub_features: yes
      include_management_tools: yes
    register: win_feature

  - name: reboot if installing Web-Server feature requires it
    win_reboot:
    when: win_feature.reboot_required

  - name: Run Powershell script and return json including zip file name
    script: files/script.ps1
    register: result

  - set_fact: filename={{result.stdout_lines}}
  - debug: var=result
  - debug: var=filename

  - name: copy files
    win_copy:
      src: C:\Temp\"{{ filename }}"
      dest: C:\Inetpub


Output snippet from running the play is as per below....

TASK [set_fact] 
***************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
task path: /etc/ansible/playbooks/test1/test.yml:22
 [WARNING]: ansible_winrm_cert_validation unsupported by pywinrm (is an 
up-to-date version of pywinrm installed?)

ok: [servername] => {
    "ansible_facts": {
        "filename": [
            "{",
            "    \"Name\":  \"latest-ansible v0.1.zip\"",
            "}"
        ]
    },
    "changed": false
}

TASK [debug] 
******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
task path: /etc/ansible/playbooks/test1/test.yml:23
 [WARNING]: ansible_winrm_cert_validation unsupported by pywinrm (is an 
up-to-date version of pywinrm installed?)

ok: [servername] => {
    "result": {
        "changed": true,
        "failed": false,
        "rc": 0,
        "stderr": "",
        "stdout": "{\r\n    \"Name\":  \"latest-ansible 
v0.1.zip\"\r\n}\r\n",
        "stdout_lines": [
            "{",
            "    \"Name\":  \"latest-ansible v0.1.zip\"",
            "}"
        ]
    }
}

TASK [debug] 
******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
task path: /etc/ansible/playbooks/test1/test.yml:24
 [WARNING]: ansible_winrm_cert_validation unsupported by pywinrm (is an 
up-to-date version of pywinrm installed?)

ok: [servername] => {
    "filename": [
        "{",
        "    \"Name\":  \"latest-ansible v0.1.zip\"",
        "}"
    ]
}

TASK [copy files] 
*************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
task path: /etc/ansible/playbooks/test1/test.yml:26
 [WARNING]: ansible_winrm_cert_validation unsupported by pywinrm (is an 
up-to-date version of pywinrm installed?)

The full traceback is:
Traceback (most recent call last):
  File 
"/usr/lib/python2.7/dist-packages/ansible/plugins/action/win_copy.py", line 
398, in run
    source = self._find_needle('files', source)
  File 
"/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 
999, in _find_needle
    return self._loader.path_dwim_relative_stack(path_stack, dirname, 
needle)
  File "/usr/lib/python2.7/dist-packages/ansible/parsing/dataloader.py", 
line 322, in path_dwim_relative_stack
    raise AnsibleFileNotFound(file_name=source, paths=[to_text(p) for p in 
search])
AnsibleFileNotFound: Could not find or access 'C:\Temp\"[u'{', u'    
"Name":  "latest-ansible v0.1.zip"', u'}']"'
Searched in:
        /etc/ansible/playbooks/test1/files/C:\Temp\"[u'{', u'    "Name":  
"latest-ansible v0.1.zip"', u'}']"
        /etc/ansible/playbooks/test1/C:\Temp\"[u'{', u'    "Name":  
"latest-ansible v0.1.zip"', u'}']"
        /etc/ansible/playbooks/test1/files/C:\Temp\"[u'{', u'    "Name":  
"latest-ansible v0.1.zip"', u'}']"
        /etc/ansible/playbooks/test1/C:\Temp\"[u'{', u'    "Name":  
"latest-ansible v0.1.zip"', u'}']"

fatal: [servername]: FAILED! => {
    "changed": false,
    "dest": "C:\\Inetpub",
    "msg": "Could not find or access 'C:\\Temp\\\"[u'{', u'    \"Name\":  
\"latest-ansible v0.1.zip\"', u'}']\"'\nSearched 
in:\n\t/etc/ansible/playbooks/test1/files/C:\\Temp\\\"[u'{', u'    
\"Name\":  \"latest-ansible v0.1.zip\"', 
u'}']\"\n\t/etc/ansible/playbooks/test1/C:\\Temp\\\"[u'{', u'    \"Name\":  
\"latest-ansible v0.1.zip\"', 
u'}']\"\n\t/etc/ansible/playbooks/test1/files/C:\\Temp\\\"[u'{', u'    
\"Name\":  \"latest-ansible v0.1.zip\"', 
u'}']\"\n\t/etc/ansible/playbooks/test1/C:\\Temp\\\"[u'{', u'    \"Name\":  
\"latest-ansible v0.1.zip\"', u'}']\"",
    "src": "C:\\Temp\\\"[u'{', u'    \"Name\":  \"latest-ansible 
v0.1.zip\"', u'}']\""
}
        to retry, use: --limit @/etc/ansible/playbooks/test1/test.retry


What I am trying to do is copy the zip file to a different directory on the 
same server, create a new folder with name captured in the value in the 
json output of filename (excluding the .zip - I.E latest-ansible v0.1) and 
then extract the contents to this new folder.

What do I need to change in my playbook syntax to get this file copy to 
work leveraging the value in the json output? After I've got this sorted I 
can tackle the next hurdle :-)

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e21a6376-8f7b-4788-b2a3-26e32b142125%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to