---
---
- name: Install Zabbix-agent
hosts: all
remote_user: root
tasks:
- name: Check and Print Linux OC
debug: var=ansible_os_family
- block: #Block for Centos
- name: Install Apache Centos
yum: name=httpd state=installed
- name: Apache UP Centos
service: name=httpd state=started enabled=yes
when: ansible_os_family == "RedHat"
- block: #Block for Debian
- name: Install Apache Debian
apt: name=apache2 update_cache=yes state=latest
- name: Apache UP Debian
service: name=apache2 state=started enabled=yes
when: ansible_os_family == "Debian"
ansible-playbook playbook_test.yml
PLAY [Install Zabbix-agent] ******************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
[WARNING]: Platform linux on host debvm is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [debvm]
ok: [vps-ubuntu]
ok: [centosvm]
TASK [Check and Print Linux OC] **************************************************************************************************************************************************************************************************************
ok: [debvm] => {
"ansible_os_family": "Debian"
}
ok: [centosvm] => {
"ansible_os_family": "RedHat"
}
ok: [vps-ubuntu] => {
"ansible_os_family": "Debian"
}
TASK [Install Apache Centos] *****************************************************************************************************************************************************************************************************************
skipping: [debvm]
skipping: [vps-ubuntu]
ok: [centosvm]
TASK [Apache UP Centos] **********************************************************************************************************************************************************************************************************************
skipping: [debvm]
skipping: [vps-ubuntu]
ok: [centosvm]
TASK [Install Apache Debian] *****************************************************************************************************************************************************************************************************************
skipping: [centosvm]
ok: [debvm]
ok: [vps-ubuntu]
TASK [Apache UP Debian] **********************************************************************************************************************************************************************************************************************
skipping: [centosvm]
ok: [debvm]
ok: [vps-ubuntu]
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
centosvm : ok=4 changed=0 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
debvm : ok=4 changed=0 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
vps-ubuntu : ok=4 changed=0 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
drwx------
обе директории. -rw-r--r-- - файл.
Т.е. было вот так
А нужно, чтобы when находился строго под block