Ansible 错误';寄存器';不是游戏的有效属性
我是ansible的新手,我写了一本剧本,将用于检查和安装多台机器的内核升级,但我一直遇到下面的问题Ansible 错误';寄存器';不是游戏的有效属性,ansible,Ansible,我是ansible的新手,我写了一本剧本,将用于检查和安装多台机器的内核升级,但我一直遇到下面的问题 *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 o
*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*
这是我的剧本里的内容
---
# 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
我认为问题在于你没有正确地定义一组任务,你是在尝试使用角色扮演还是常规角色扮演?因为你写的结构看起来更像是一个角色,但是给你的错误看起来像是被称为一个常规的剧本,而不是一个角色。也许这有助于我想说的: 我只测试了影响我的代码,我就是这样写的,它为我修复了错误,但可以肯定的是,这就像一个剧本,而不是一个角色:
- hosts: localhost
tasks:
- name: "View current kernel version"
command: uname -mrs
register: uname_result
- name: print
debug:
msg: "{{ uname_result }}"
您的剧本不尊重yaml和/或ansible语法。请注意缩进和新行。您还应该通读以学习基本概念和语法。你可以在发布之前验证你的剧本。嗨,这就是我正在忙的事情,因为我说我是新来的。这是我与ansible合作的第二天,感谢ansible lint的提示。这非常方便。我是的,这确实是我想要扮演的角色,我是作为一个常规角色来运行它的