0

I'm fairly new to ansible, i wrote a playbook that will be used for checking and installing kernel upgrades for multiple machines but I keep running into the issue below.

  *ERROR! 'register' is not a valid attribute for a Play
The error appears to have been in '/etc/ansible/kernel_upgrade/tasks/main.yml': line 4, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
  - name: View current kernel version
    ^ here*

here is what I have in my playbook.

---
# tasks file for kernel_upgrade

  - name: View current kernel version
    command: uname -mrs
    register: uname_result

  - debug: msg="{{uname_result.stdout_lines}}"
    tags:
      - current kernel versions

  - name: update kernel version
    apt:
      update_cache: yes
      upgrade: dist
      when: ansible_distribution == 'Ubuntu'
      tags:
       - Upgrading kernel Ubuntu

  - name: update kernel CentOS
    yum:
      update_cache: yes
      upgrade: dist
      when: ansible_distribution == 'CentOS'
      tags:
       - Upgrading Kernel CentOS

  - name: Reboot box if kernel/libs updated and requested by the system
    shell: sleep 10 && /sbin/shutdown -r now
    args:
       removes: /var/run/reboot-required
       async: 300
       poll: 0
       ignore_errors: true
       tags:
        - system reboot to apply latest patches


  - name: Wait for system to become reachable again
    wait_for_connection:
      delay: 60
      timeout: 300
      tags:
       - wait for system to become reachable again

  - name: Verify new update
    command: uname -mrs
    register: uname_result
    tags:
       - verifying new update

  - name: Display new kernel version
    debug: msg="{{uname_result.stdout_lines}}"
    tags:
       - new kernel version

...

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
oom koosie
  • 11
  • 1
  • 2
  • Your playbook does not respect yaml and/or ansible syntax. Please [take Y minutes to learn yaml](https://learnxinyminutes.com/docs/yaml/) and pay attention to indentation and new lines. You should also read through the [Intro to playbooks](https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#about-playbooks) to learn the basic concepts and syntax. You can validate your playbooks with [yamllint](https://yamllint.readthedocs.io/en/stable/) and [ansible-lint](https://docs.ansible.com/ansible-lint/) prior to posting. – Zeitounator Nov 30 '20 at 08:51
  • hi that is what I'm busy with as i said I'm new to this this is my second day working with ansible, thanks for the tip on ansible-lint this is very handy – oom koosie Nov 30 '20 at 15:13

1 Answers1

1

I think the problem is that you are not defining a set of tasks properly, are you trying to use a role or a regular play? because the structure you write seems more like a role, but the error is giving to you seems like is being called like a regular play instead of a role. Maybe that helps what I'm trying to say: Ansible Playbooks vs Roles

I only tested the affecting code I wrote it like that and it fixed the error for me, but for sure this is working like a playbook instead like a role:

- hosts: localhost

  tasks:
    - name: "View current kernel version"
      command: uname -mrs
      register: uname_result

    - name: print
      debug:
        msg: "{{ uname_result }}"
ikora
  • 772
  • 3
  • 16