I have the following code which runs on localhost (linux OS), but needs to delegate some actions to a windows server.
When I run the playbook, I give in input the vault folder which contains the credentials to connect to the windows server. The problem is that, on the "rescue" part, I call a task called error_thrower.yml
which requires a connection via SSH to localhost. At this part, I have an error because it does not find the right credentials on the vault to connect to localhost which has a Linux OS. The error : fatal: [localhost -> localhost]: UNREACHABLE! =>
.
- name: Disk Saturation
hosts: localhost
gather_facts: no
tasks:
- name: 'Actions on the server'
delegate_to: "{{ target }}" #Windows server
block:
- name: 'Server connection test'
win_ping:
register: test_connection
ignore_errors: yes
ignore_unreachable: yes
- name: 'Check total space of the disk'
ansible.windows.win_shell: "Get-Volume -DriveLetter {{ partition_name }} | Select-Object Size | ConvertTo-Json"
register: totalspace
rescue: 'Error thrower call'
- name:
ansible.builtin.include_role:
name: common
tasks_from: error_thrower.yml
vars:
fail_message: Server is not accessible
error_name: server_unreachable
message_details: "{{ test_connection.msg }}"
when: test_connection.unreachable is defined
Is there a way in Ansible to give two different credentials in the vault so it can have information to connect to both machines ?