@Benedictus

Как исправить ошибку The task includes an option with an undefined variable в Ansible?

Добрый день.

Помогите разобраться с Ansible новичку. Есть вот такой простой playbook найденный на просторах интернета:
---
- hosts: test
tasks:

- name: Debug
debug:
msg={{ ansible_os_family }}

- set_fact: package_name=httpd
when: ansible_os_family == "Redhat"

- set_fact: package_name=apache2
when: ansible_os_family == "Debian"

- name: Install httpd package
yum: name={{ package_name }} state=latest
when: ansible_os_family == "Redhat"

- name: Debug1
debug: msg={{ package_name }}

- name: Install apache2 package
apt: name={{ package_name }} state=latest
when: ansible_os_family == "Debian"

выполнение которого завершается ошибкой:

PLAY [test] *************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************
ok: [192.168.0.76]
ok: [192.168.0.79]

TASK [Debug] ************************************************************************************************************************************************
ok: [192.168.0.79] => {
"msg": "RedHat"
}
ok: [192.168.0.76] => {
"msg": "RedHat"
}

TASK [set_fact] *********************************************************************************************************************************************
skipping: [192.168.0.79]
skipping: [192.168.0.76]

TASK [set_fact] *********************************************************************************************************************************************
skipping: [192.168.0.79]
skipping: [192.168.0.76]

TASK [Install httpd package] ********************************************************************************************************************************
skipping: [192.168.0.79]
skipping: [192.168.0.76]

TASK [Debug1] ***********************************************************************************************************************************************
fatal: [192.168.0.79]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'package_name' is undefined\n\nThe error appears to be in '/etc/ansible/playbooks/install_apache.yml': line 19, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Debug1\n ^ here\n"}
fatal: [192.168.0.76]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'package_name' is undefined\n\nThe error appears to be in '/etc/ansible/playbooks/install_apache.yml': line 19, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Debug1\n ^ here\n"}

PLAY RECAP **************************************************************************************************************************************************
192.168.0.76 : ok=2 changed=0 unreachable=0 failed=1 skipped=3 rescued=0 ignored=0
192.168.0.79 : ok=2 changed=0 unreachable=0 failed=1 skipped=3 rescued=0 ignored=0

полагаю что тут проблема в синтаксисе, но никак не могу понять что нужно исправить...
  • Вопрос задан
  • 3159 просмотров
Решения вопроса 1
@MaxKozlov
Redhat и RedHat - это две большие разницы :)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы