Your files are lower cased, ansible_distribution is not.

To match your other logic, you probably want to do this:

include_tasks: "{{ ansible_distribution|lower }}-ntp.yaml"


On Tue, Jul 9, 2019 at 1:38 PM Keith Mills <[email protected]> wrote:

> I am new to Ansible!
>
>
> I'm working on an NTP Install/Configure Project. I have a main.yaml file,
> a ntp.yaml playbook and 4 tasks (debian-ntp.yaml, redhat-ntp.yaml,
> sles-ntp.yaml, ubuntu-ntp.yaml). I can't seem to get this to work.
>
>
> ansible --version
> ansible 2.8.0
>   config file = /etc/ansible/ansible.cfg
>   configured module search path = [u'/home/kjames/.ansible/plugins/modules', 
> u'/usr/share/ansible/plugins/modules']
>   ansible python module location = /usr/lib/python2.7/site-packages/ansible
>   executable location = /usr/bin/ansible
>   python version = 2.7.5 (default, Apr  9 2019, 14:30:50) [GCC 4.8.5 20150623 
> (Red Hat 4.8.5-36)]
>
> cat /etc/os-release
> NAME="CentOS Linux"
> VERSION="7 (Core)"
> ID="centos"
> ID_LIKE="rhel fedora"
> VERSION_ID="7"
> PRETTY_NAME="CentOS Linux 7 (Core)"
>
> What I have:
>
>
> roles/base/tasks/main.yaml:
>
>
> ---
> ## PLAYBOOK TO INSTALL AND CONFIGURE NTP ON REDHAT/ DEBIAN SYSTEMS
>
>     - name: Include OS-specific variables
>       include_vars: "{{ ansible_distribution }}.yaml"
>
>     - include: redhat-ntp.yaml
>       when: ansible_distribution|lower == 'redhat'
>
>     - include: debian-ntp.yaml
>       when: ansible_distribution|lower == 'debian'
>
>     - include: sles-ntp.yaml
>       when: ansible_distribution|lower == 'sles'
>
>     - include: ubuntu-ntp.yaml
>       when: ansible_distribution|lower == 'ubuntu'
>
>     - name: Set the correct timezone
>       file: src={{ ntp_timezone }}  dest=/etc/localtime state=link force=yes
>
>     - name: Configure NTP
>       template: src={{ item }} dest={{ ntp_config }}
>       with_first_found:
>        - "../templates/{{ ansible_distribution }}-{{ 
> ansible_distribution_version }}.ntp.conf.j2"
>        - "../templates/{{ ansible_distribution }}.ntp.conf.j2"
>        - "../templates/{{ ansible_os_family }}.ntp.conf.j2"
>        - "../templates/ntp.conf.j2"
>
>     #- name: Restart NTP
>     ##  service: name={{ ntp_service }} state=restarted
>     #
>     - name: Force NTP update
>       shell: "service {{ ntp_service }} stop && ntpdate -s {{ ntpdate_server 
> }} && service {{ ntp_service }} start"
>     ...
>
> roles/base/tasks/ntp.yaml:
>
> ---
> - hosts: all
>   remote_user: root
>
>   tasks:
>   - name: Detect OS and run appropriate tasks
>     include_tasks: "{{ ansible_distribution }}-ntp.yaml"
>
> roles/base/tasks/debian-ntp.yaml:
>
> ---
> - name: Ensure NTP packages are installed (debian).
>   apt: "name={{ ntp_package }} state=installed"
>
> roles/base/tasks/redhat-ntp.yaml:
>
> ---
> - name: Ensure NTP packages are installed (redhat).
>   yum: "name={{ ntp_package }} state=installed"
>
> roles/base/tasks/sles-ntp.yaml:
>
> ---
> - name: Ensure NTP packages are installed (sles).
>   zypper: "name={{ ntp_package }} state=installed"
>
> roles/base/tasks/ubuntu-ntp.yaml:
>
> ---
> - name: Ensure NTP packages are installed (ubuntu).
>   apt: "name={{ ntp_package }} state=installed"
>
> Should install and configure ntp on all (RedHat, SLES, Debian, Ubuntu).
>
>
> Error:
>
>
> TASK [Detect OS and run appropriate tasks]
> ******************************************************************************************************************************
> fatal: [ablrh7ex6499]: FAILED! => {"reason": "Could not find or access
> '/home/jamekeit/ds9/roles/base/tasks/RedHat-ntp.yaml' on the Ansible
> Controller."} fatal: [abls15ex8401]: FAILED! => {"reason": "Could not find
> or access '/home/jamekeit/ds9/roles/base/tasks/SLES-ntp.yaml' on the
> Ansible Controller."} fatal: [abldeb8ex6658]: FAILED! => {"reason": "Could
> not find or access '/home/jamekeit/ds9/roles/base/tasks/Debian-ntp.yaml' on
> the Ansible Controller."}
>
>
> I don't understand why I'm getting this because I have all the files on
> the Ansible Controller (debian-ntp.yaml, redhat-ntp.yaml, sles-ntp.yaml,
> ubuntu-ntp.yaml)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/977898a1-60cf-482c-beec-bd36834d4101%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/977898a1-60cf-482c-beec-bd36834d4101%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Matt Martz
@sivel
sivel.net

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v8hntXX62AiZit2LhVMkPH5XbrDFxpdkj-0wyjPwyW6fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to