Running local play with winrm config

637 views
Skip to first unread message

Jordan Borean

unread,
Jun 16, 2016, 9:01:23 AM6/16/16
to Ansible Project
Hi

I am having issues trying to create a play that will setup a Windows EC2 instance and then install software once it is up. For linux instances I do the following to create a new instance on the localhost and then run the other roles on the new instance once it is ready.

---
- name: create new aws ec2 instance
  hosts
: localhost
  become
: False
  vars_files
:
   
- group_vars/tag_Application_alfred-linux.yml
   
- group_vars/tag_Environment_dev.yml
  roles
:
   
- common/aws-create-instance


- name: setup newly created instances
  hosts
: "{{ hostvars['localhost']['new_ec2_hosts_string'] }}"
  roles
:
   
- common/stash-user-setup
   
- jdk/install-linux
   
- maven/install-linux
   
- alfred/linux-setup

When trying the same thing for my Windows hosts Ansible fails to run a play on the localhost with the following error.

(py27)[appuser@jdbrd2 treasury-ansible]$ ansible-playbook test.yml --ask-vault-pass
Vault password:


PLAY
[localhost] ***************************************************************


TASK
[setup] *******************************************************************
fatal
: [localhost]: UNREACHABLE! => {"changed": false, "msg": "ssl: HTTPSConnectionPool(host='127.0.0.1', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f6743985ad0>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
        to
retry, use: --limit @test.retry


PLAY RECAP
*********************************************************************
localhost                  
: ok=0    changed=0    unreachable=1    failed=0


I believe it is because one of the vars_files that are being pulled in contains the following variables;
# Ansible Connection details
ansible_user: User@domain
ansible_password: "{{ vault_alfred_windows_account_password }}"
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
ansible_winrm_transport: ntlm

I cannot seem to override the ansible_connection: winrm to ssh or smart when running the root play. Does anyone know of a way to run a whole roles entirely on the localhost and overridin the ansible_connection: winrm just for that local host. I have tried the following;
  • Setting ansible_connection: smart in the host_vars/localhost.yml file
  • Setting connection: smart or ssh after defining hosts: localhost in the root play
  • Setting the variable ansible_connecton: ssh or ansible_connection: smart in the vars: section after pulling in the vars_files

J Hawkesworth

unread,
Jun 16, 2016, 10:29:46 AM6/16/16
to Ansible Project
I think you should set up your inventory in a manner similar to what is described in the windows introduction.


put the windows-specific connection vars into a group and then when you want to do things to a windows host, use the windows group name for the hosts: line in your play.

By doing

  vars_files:
    
- group_vars/tag_Application_alfred-linux.yml
    
- group_vars/tag_Environment_dev.yml

you are forcing the vars in the group_vars folder to apply to all hosts.


Hope this helps,

Jon

Jordan Borean

unread,
Jun 16, 2016, 10:37:35 AM6/16/16
to Ansible Project
Thanks for the suggestion, the trouble I am having is that I want to create the instance from ec2 and all my hosts are gotten dynamically. Are you suggesting I split up my config so the aws variables are in one file and then my tagged application details are in another which contains the connection details. Is there a better way to do it as I feel like maintaining multiple config files can get difficult as it grows in the future.

Thanks

Jordan

J Hawkesworth

unread,
Jun 17, 2016, 9:41:21 AM6/17/16
to Ansible Project
Sounds like my ansible setup is rather different from yours, but I have wound up with a handful of config files for each environment - ones that configure connections to hosts I always keep separate from 'business' type vars.

I don't know if using the add_host module http://docs.ansible.com/ansible/add_host_module.html might help you to create a bunch of windows hosts, then add them to a windows group so they get the right vars when you try to connect to them.

Hope this helps

Jon
Reply all
Reply to author
Forward
0 new messages