Hi Team,
We are trying to automate the installation of tools in azure using ansible. VM spin up is successful and we are trying to invoke the powershell script(code for tools installation) so the files has to be installed on the server.
Tried number of ways using win_copy command for copying the files to remote server but no luck.
ANSIBLE VERSION:
ansible 2.7.9
config file = None
ansible python module location = /opt/ansible/local/lib/python2.7/site-packages/ansible
executable location = /opt/ansible/bin/ansible
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
Below is the code snippet used for copying files from local to remote server:
- name: Copy script from local to remote server
win_copy:
src: files
dest: C:\
register: myfile
- debug: var=myfile
- win_command: powershell.exe -ExecutionPolicy ByPass -File C:/userdata-winsetup.ps1
Below are the inventory file details:
[windows]
127.0.0.1
[windows:vars]
ansible_user: admin
ansible_password: admin
ansible_connection: winrm
ansible_winrm_transport: basic
ansible_port: 5986
ansible_winrm_server_cert_validation: ignore
validate_certs: false
Results while running ansible playbook:
fatal: [localhost]: FAILED! => {
"changed": false,
"dest": "C:\\",
"module_stderr": "",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"operation": "folder_copy",
"rc": 0,**_
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4aa2d698-e3c0-41ae-8739-916e988abac0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi ,Error says in dest. Can you try to put in any other destination with absolute path ?
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8254df4c-e104-405f-b9b8-08080ce5e0e0%40googlegroups.com.
its a module failure...is the localhost linux or windows.???...win_copy works for windows ...for rest use copy module
On Fri, 12 Apr 2019, 14:02 gottumukkala srija, <srij...@gmail.com> wrote:
Hi Jordan,--Can you please describe it briefly? You want us to create a new VM and then point that IP to add_host?
On Thursday, April 11, 2019 at 12:30:28 PM UTC+5:30, Jordan Borean wrote:If your inventory is targeting localhost then that means it's trying to run a Windows module on the Ansible controller which won't work. You cna use the azure_rm_virtualmachine module to spin up a host but then you will have to use something like 'add_host' [1] to add the host for the current execution then change the play to that new host.ThanksJordan
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 ansible...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3ca787be-1724-4329-8dc1-1e5c58371122%40googlegroups.com.
If u want to copy from local to remote u should mention -host: remote_host....i think u r using localhost
On Fri, 12 Apr 2019, 14:36 gottumukkala srija, <srij...@gmail.com> wrote:
localhost is windows. And we are using win_copy for copying the file. Any alternative for this?--
On Friday, April 12, 2019 at 2:27:27 PM UTC+5:30, CORLEONE## wrote:its a module failure...is the localhost linux or windows.???...win_copy works for windows ...for rest use copy moduleOn Fri, 12 Apr 2019, 14:02 gottumukkala srija, <srij...@gmail.com> wrote:Hi Jordan,--Can you please describe it briefly? You want us to create a new VM and then point that IP to add_host?
On Thursday, April 11, 2019 at 12:30:28 PM UTC+5:30, Jordan Borean wrote:If your inventory is targeting localhost then that means it's trying to run a Windows module on the Ansible controller which won't work. You cna use the azure_rm_virtualmachine module to spin up a host but then you will have to use something like 'add_host' [1] to add the host for the current execution then change the play to that new host.ThanksJordan
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 ansible...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8254df4c-e104-405f-b9b8-08080ce5e0e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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 ansible...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
- name: Copy script from local to remote server
win_copy:
src: files
dest: C:\
register: myfile
- debug: var=myfile
- win_command: powershell.exe -ExecutionPolicy ByPass -File C:/userdata-winsetup.ps1
3. The directory where your playbook and inventory file reside also have a directory called "files".
[windows]
127.0.0.1
Based on your inventory file, you're attempting to run the commands in the playbook on the system you're running Ansible on. Your inventory file probably needs the _windows_ server listed in the "[windows]" section like this:
[windows]
Then when you run your playbook with Ansible, it will connect using the "winrm" protocol and login with "admin" (password: "admin"), then copy the files from ".\files\" to "c:\" on the remote system.
Once you've validated all that, please re-run the playbook with "-v" (or more for additional verbose output) and post it here.
Thanks,
DanL
[WARNING]: Unable to parse /home/f2/.ansible/inventory as an inventory source[WARNING]: No inventory was parsed, only implicit localhost is available[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[windows]
[windows:vars]
ansible_connection=winrm
ansible_port=5986
ansible_winrm_transport=ntlm
ansible_winrm_server_cert_validation=ignore
- name: provision Windows host in Azure
hosts: localhost
gather_facts: no
vars:
azure_resource_group: RG01
azure_vm_name: WindowsVM01
windows_username: azure
windows_password: 's=3@W%qTDYtm%nWW'
tasks:
# This is not a full task, you still need to do the work around creating the resource group and other components.
# This is just a brief example to show you how to provision the Windows host, enable WinRM, and then connect to it
# with Ansible.
- name: provision Windows VM
azure_rm_virtualmachine:
admin_username: '{{ windows_username }}'
admin_password: '{{ windows_password }}'
os_type: Windows
image:
offer: WindowsServer
publisher: MicrosoftWindowsServer
sku: 2016-Datacenter
version: latest
name: '{{ azure_vm_name }}'
resource_group: '{{ azure_resource_group }}'
state: present
register: azure_vm
- name: set fact for VM extension PS script to run
set_fact:
# You should be sourcing your own script and not this one on GitHub. This is just an example of how to download
# a PS script from a URL and then invoke it using the VM extension.
azure_vm_extension_ps: Invoke-Expression -Command ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))
- name: set fact for VM extension setings
azure_vm_extension:
commandToExecute: powershell.exe -ExecutionPolicy ByPass -EncodedCommand {{ azure_vm_extension_ps | string | b64encode(encoding='utf-16-le') }}
- name: set fact for newly create VM public IP address
set_fact:
azure_vm_ip: '{{ azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}'
- name: create Azure VM extension to enable HTTPS WinRM listener
azure_rm_virtualmachine_extension:
name: winrm-extension
resource_group: '{{ azure_resource_group }}'
virtual_machine_name: '{{ azure_vm_name }}'
publisher: Microsoft.Compute
virtual_machine_extension_type: CustomScriptExtension
type_handler_version: 1.9
settings: '{{ azure_vm_extension | to_json }}'
auto_upgrade_minor_version: yes
- name: wait for the WinRM port to come online
wait_for:
port: 5986
host: '{{ azure_vm_ip }}'
timeout: 600
- name: add new Azure VM as a Windows host
add_host:
name: '{{ azure_vm_ip }}'
groups: windows
ansible_user: '{{ windows_username }}'
ansible_password: '{{ windows_password }}'
# Now that we have provisioned our new Windows host and added it to the in memory host inventory, we change our play
# to run on the windows group and then run our script
- name: deploy configuration to Windows host in Azure
hosts: windows
gather_facts: no
tasks:
- name: wait for the WinRM connection to be fully reachable
wait_for_connection:
- name: gather facts about host
setup:
# Your example had you copying the script with win_copy then invoking it. Unless there were other files there, it is
# simpler to just use script instead.
- name: invoke setup script
script: userdata-winsetup.ps1