I am trying to execute this Playbook:
---
- name: Configure System for Oracle 19
vars_prompt:
- name: setup_test
prompt: "Configure System for Test or Production? [Test/Prod]: "
default: Test
private: no
vars_files:
- /etc/ansible/roles/oracle_19_test/defaults/main.yml
- hosts: "{{ Appserver_STBY }}"
tasks:
- name: tnsnames auf Appserver anpassen
template:
src: tnsnames_Appserver.ora.j2
dest: /opt/oracle/app/oracle/product/11.2.0/client_1/network/admin/tnsnames.ora
owner: oracle
group: oinstall
mode: 0644
backup: yes
- hosts: "{{ Floorserver }}"
tasks:
- name: tnsnames auf Floorserver anpassen
template:
src: /etc/ansible/roles/oracle_19_test/templates/tnsnames_Floor.ora.j2
dest: /u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora
owner: oracle
group: oinstall
mode: 0644
backup: yes
tags: floortest
No matter what I try to do, when I execute the playbook I get the Prompt for the Variable (although it is not of use now) and immediately after I get ERROR! the field 'hosts' is required but was not set
The hosts should be taken from variables which are defined in that var file. At first I created a Role, but then I realized that roles cannot run on multiple host sections. Can someone help me? According to YAML Checker this is valid Syntax, and I provided the hosts.
EDIT: So I changed my Playbook to this:
---
- hosts: "{{ Appserver_STBY }}"
vars_files:
- /etc/ansible/group_vars/all
tasks:
- name: tnsnames auf Appserver anpassen
template:
src: tnsnames_Appserver.ora.j2
dest: /opt/oracle/app/oracle/product/11.2.0/client_1/network/admin/tnsnames.ora
owner: oracle
group: oinstall
mode: 0644
backup: yes
- hosts: "{{ Floorserver }}"
# vars_files:
# - /etc/ansible/group_vars/all
tasks:
- name: tnsnames auf Floorserver anpassen
template:
src: /etc/ansible/roles/oracle_19_test/templates/tnsnames_floor.ora.j2
dest: /u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora
owner: oracle
group: oinstall
mode: 0644
backup: yes
tags: floortest
If I include the variables for every hosts section it works. So now I tried to create a group_vars/all file relative to inventory. If i load the File manually it works. If i dont load it manually , the File will not be loaded and the Section with the Variables in Hostname will fail with:
ERROR! The field 'hosts' has an invalid value, which includes an undefined variable. The error was: 'Floorserver' is undefined
But inside my group_vars/all file the variable is declared:
# Floorserver Hosts
Floorserver: hostxyz
I still dont know what I am doing wrong..