I'm pretty new with Ansible so I might configured things wrong
[I have a Docker container running Ansible service in CentOS8
I have an Ansible repository that include the Ansible files (this is a .Git repository]
My will was to automatically revert each lab (the lab is composed of 8 vms, 5 windows server 2016 and 3 windows 10. The DC include policy to enable winrm in those machines) in vCenter server to a specific snapshot. But first I'm trying to: once power-off the lab's machines when they're turned-on and once power-on the lab's machines when they're turned-off
So, I (with the help of ansible-roles-explained-with-examples guide):
- Created a role with
ansible-galaxy init
command name vcenter
(see directory tree below)
- Created some vcenter tasks files inside
tasks
folder (see directory tree below). Here is an example of poweroff.yml
and poweron.yml
tasks files:
- name: Set the state of a virtual machine to poweroff
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: "/{{ datacenter_name }}/vm/{{ folder }}"
name: "{{ ansible_hostname }}"
# name: "{{ guest_name }}"
validate_certs: no
state: powered-off
force: yes
delegate_to: localhost
register: deploy
- name: Set the state of a virtual machine to poweron using MoID
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
folder: "/{{ datacenter_name }}/vm/{{ folder }}"
name: "{{ ansible_hostname }}"
# moid: vm-42
validate_certs: no
state: powered-on
delegate_to: localhost
register: deploy
- Supplied vCenter credentials in
vcenter\vars\main.yml
file, like this:
# vars file for vcenter
vcenter_hostname: vcenter.foo.com
vcenter_username: [email protected]
vcenter_password: f#0$o#1$0o
datacenter_name: FOO_Fighters
# datastore_name:
cluster_name: FOO
folder: '/FOO/PRODUCT/DOMAIN.COM/'
- Included the tasks in
tasks\main.yml
file with import-task
key, like this:
---
# tasks file for roles/vcenter
- import_tasks: poweroff.yml
# - import_tasks: poweron.yml
# - import_tasks: revert.yml
# - import_tasks: shutdown.yml
- Created a
all.yml
inside group_vars folder in inventories library (i don't know if its a professional way to do like that) that include all winrm details like this:
---
#WinRM Protocol Details
ansible_user: DOMAIN\user
ansible_password: f#0$o#1$0o
ansible_connection: winrm
ansible_port: 5985
ansible_winrm_scheme: http
ansible_winrm_server_cert_validation: ignore
ansible_winrm_transport: ntlm
ansible_winrm_read_timeout_sec: 60
ansible_winrm_operation_timeout_sec: 58
- Created a
revert_lab.yml
playbook that include the role, like this
---
- name: revert an onpremis lab
hosts: all
roles:
- vcenter
My ansible.cfg
is like this:
[defaults]
inventory = /ansible/inventories
roles_path = ./roles:..~/ansible/roles
I executed the playbook successfully to poweroff all the machines in the lab, then I "turned on" the poweron task in the role, like that:
---
# tasks file for roles/vcenter
# - import_tasks: poweroff.yml
- import_tasks: poweron.yml
# - import_tasks: revert.yml
# - import_tasks: shutdown.yml
Now that the all lab's machines are shutdown, executing the playbook, give the following error:
PLAY [revert vmware vcenter lab] *************************************************
TASK [Gathering Facts] ***********************************************************
fatal: [vm1.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm:
HTTPConnectionPool(host='vm1.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae4908d0>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
fatal: [vm2.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPConnectionPool(host='vm2.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae487b00>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
fatal: [vm3.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPConnectionPool(host='vm3.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae48acc0>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
fatal: [vm4.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPConnectionPool(host='vm4.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae48de80>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
fatal: [vm5.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm:
HTTPConnectionPool(host='vm5.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae41f080>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
fatal: [vm6.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPConnectionPool(host='vm6.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae41d7f0>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
fatal: [vm7.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPConnectionPool(host='vm7.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae428048>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
fatal: [vm8.domain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm: HTTPConnectionPool(host='vm8.domain.com', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb7ae425588>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true}
PLAY RECAP ***********************************************************************
vm1.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
vm2.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
vm3.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
vm4.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
vm5.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
vm6.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
vm7.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
vm8.domain.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
Why the poweroff task works OK and poweron doesn't? How can I fix this issue?
My repository:
C:.
├───ansible
│ │ ansible.cfg
│ ├───inventories
│ │ └───test
│ │ ├───cloud
│ │ └───onpremis
│ │ └───domain.com
│ │ │ lab_j.yml
│ │ │ lab_r.yml
│ │ └───group_vars
│ │ all.yml
│ ├───playbooks
│ │ revert_lab.yml
│ └───roles
│ └───vcenter
│ ├───tasks
│ │ main.yml
│ │ poweroff.yml
│ │ poweron.yml
│ │ revert.yml
│ │ shutdown.yml
│ └───vars
│ main.yml
My inventory lab_r.yml
- this is a partial schema
---
all:
children:
root:
children:
center:
children:
appservers:
hosts:
vm1.domain.com:
qservers:
hosts:
vm2.domain.com:
dbservers:
hosts:
vm3.domain.com: