Skip to content

Instantly share code, notes, and snippets.

@kagarlickij
Created January 24, 2020 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagarlickij/92683649b580333a111ddbd738f1e9d1 to your computer and use it in GitHub Desktop.
Save kagarlickij/92683649b580333a111ddbd738f1e9d1 to your computer and use it in GitHub Desktop.
Sample Ansible playbook that uses Windows hostname for creating file and running command
var1: {{ var1 }}
var2: {{ ansible_hostname }}

ansible-playbook -vvvv -i hosts playbook.yml --extra-vars='ansible_user=ansible ansible_password=A****0+ ansible_connection=winrm ansible_winrm_server_cert_validation=ignore var1=value1'

[all]
40.71.194.145
- hosts: all
vars:
var1:
var2: "$env:COMPUTERNAME"
tasks:
- name: ping
win_ping:
- name: Create file using hostname
win_template:
src: build_config_template.j2
dest: C:\build_config.txt
- name: Run command using hostname
win_shell: |
Write-Output "hello from {{ var2 }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment