Ansible ERROR! ‘import’ is not a valid attribute for a Play

Error

[root@localhost rajesh]# ansible-playbook -i inventory master.yaml -u root -k
SSH password:
ERROR! 'import' is not a valid attribute for a Play

The error appears to be in '/root/rajesh/master.yaml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- import: play1.yaml
  ^ here

[root@localhost rajesh]# ansible-playbook -i inventory master.yaml -u root -k
SSH password:
ERROR! 'include' is not a valid attribute for a Play

The error appears to be in '/root/rajesh/master.yaml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- include: play1.yaml
  ^ here

Solution

The include module has been deprecated with ansible version 2.16, because

# play1.yaml
---
- name: Install and configure web server
  hosts: web

  tasks:
    - name: Install the latest version of Apache
      ansible.builtin.yum:
        name: httpd
        state: absent
    - name: Install the latest version of Apache
      ansible.builtin.yum:
        name: httpd
        state: latest

# play2.yaml
---
- name: Install and configure web server
  hosts: web

  tasks:
    - name: Copy file with owner and permissions
      ansible.builtin.copy:
        src: index.html
        dest: /var/www/html/index.html
    - name: Start service httpd, if not started
      ansible.builtin.service:
        name: httpd
        state: started
    - name: Start service httpd, if not started
      ansible.builtin.service:
        name: firewalld
        state: stopped
        enabled: no

# master.yaml
- import_playbook: play1.yaml
- import_playbook: play2.yaml
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x