Setting task path

My current ansible playbook and roles are under /etc/Ansiblectrl01

When I try to build a new VM, using:

ansible-playbook playbooks/newvm.yaml -e “hostname=xxx” -vvvv

From:

/etc/Ansiblectrl01, it errors:

fatal: [localhost]: FAILED! => {
“ansible_facts”: {
“server”: {}
},
“ansible_included_var_files”: ,
“changed”: false,
“message”: “Could not find or access ‘/etc/ansible/servers/USAEDSADMP01.yaml’ on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option”
}

It seems to be reading the yaml file from the wrong old location for some reason /etc/ansible.

How can I fix this?

include_vars ONLY runs on the controller, not the remote, you'll have
to fetch/slurp those files and make them available on the controller
to do so.

Another way is to use 'local facts' files
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html#parameter-fact_path

Thanks, but where is that set? I dont see it in my yaml file anywhere

On your task, which you have not shared, I only know it is
include_vars due to the return data

normally if you want to get help you should show the task(s) that are
failing and as much of the -vvv output you can

This is full error:

TASK [Include vars of server.yaml file] *****************************************************************************************************************************************************************************************
task path: /etc/ansible/roles/azurebuild/tasks/main.yml:4
Thursday 21 April 2022 14:35:57 -0500 (0:00:00.020) 0:00:00.020 ********
Thursday 21 April 2022 14:35:57 -0500 (0:00:00.019) 0:00:00.019 ********
fatal: [localhost]: FAILED! => {
“ansible_facts”: {
“server”: {}
},
“ansible_included_var_files”: ,
“changed”: false,
“message”: “Could not find or access ‘/etc/ansible/servers/USAEDSADMP01.yaml’ on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option”
}

Below is my ansible.cfg:

[inventory]
enable_plugins = yaml, ini

ansible executes tasks by copying a file onto the remote host, executing it and reporting the results back to the control machine.
#With pipelining enabled, Ansible can send commands directly to STDIN through a persistent SSH connection, which is much faster than the default process.
#[ssh_connection]
pipelining = True

[defaults]

some basic default values…

inventory=./hosts
forks = 10
#find a task’s time consumption and identify which jobs are slowing down your plays
callbacks_enabled = timer, profile_tasks, profile_roles
#Facts gathering can be improved using fact caching.
#It can use redis or create JSON files on your Ansible host. Following options in the ansible.cfg file will use smart gathering and facts caching with a local json file
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp
strategy_plugins = /usr/local/lib/python3.8/dist-packages/ansible_mitogen/plugins/strategy
strategy = mitogen_linear

  • hosts: localhost
    gather_facts: no
    tasks:

  • name: Include vars of server.yaml file
    include_vars:
    file: /etc/Ansiblectrl01/servers/{{ hostname }}.yaml
    name: server

  • name: Create a network interface with dns servers
    azure_rm_networkinterface:
    name: “{{ hostname }}-nic1”
    state: present
    resource_group: ‘{{ server.az_vm_rg }}’
    enable_accelerated_networking: no
    virtual_network:
    name: ‘{{ server.az_nic_vnet }}’
    resource_group: ‘{{ server.az_vnet_rg }}’
    subnet_name: ‘{{ server.az_nic_subnet }}’
    public_ip: false
    dns_servers:

  • ‘{{ server.dnsserver1 }}’

  • ‘{{ server.dnsserver2 }}’

  • ‘{{ server.dnsserver3 }}’
    ip_configurations:

  • name: lan1
    primary: True
    private_ip_allocation_method: Static
    private_ip_address: ‘{{ server.az_vm_ipaddress }}’
    application_security_groups: ‘{{ server.az_vm_asg | default(omit) }}’
    create_with_security_group: false
    #tags: ‘{{ server.az_vm_tags }}’
    register: azure_nic
    #ignore_errors: yes