首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有处理程序的不可用任务在操作类ansible.parsing.yaml.objects.AnsibleSequence中以意外的参数类型失败

带有处理程序的不可用任务在操作类ansible.parsing.yaml.objects.AnsibleSequence中以意外的参数类型失败
EN

Stack Overflow用户
提问于 2021-01-13 14:45:51
回答 1查看 530关注 0票数 0

这是我的一个Ansible文件:

代码语言:javascript
复制
---
- name: Harden sshd configuration
  tasks:
  - name: Update /etc/ssh/sshd_config
    lineinfile:
      path: /etc/ssh/sshd_config
      regex: "{{ item.find }}"
      line: "{{ item.replace }}"
    loop:
      - { find: '^(# *)?ChallengeResponseAuthentication (yes|no)', replace: 'ChallengeResponseAuthentication no' }
      - { find: '^(# *)?PasswordAuthentication (yes|no)', replace: 'PasswordAuthentication no' }
      - { find: '^(# *)?PermitRootLogin (yes|no)', replace: 'PermitRootLogin no' }
      - { find: '^(# *)?UsePAM (yes|no)', replace: 'UsePAM no' }
    notify:
      - Restart sshd

  handlers:
    - name: Restart sshd
      service:
        name: sshd
        state: restarted

它用于封隔器的供应。

当文件运行时,我得到以下错误:

作用中的'ansible.parsing.yaml.objects.AnsibleSequence'>意外参数类型:<

代码语言:javascript
复制
==> amazon-ebs: Provisioning with Ansible...
    amazon-ebs: Setting up proxy adapter for Ansible....
==> amazon-ebs: Executing Ansible: ansible-playbook -e packer_build_name="amazon-ebs" -e packer_builder_type=amazon-ebs --ssh-extra-args '-o IdentitiesOnly=yes' -e ansible_ssh_private_key_file=/tmp/ansible-key218178175 -i /tmp/packer-provisioner-ansible080932818 /home/amedee/repos/packer-ansible-aws-linux/packer/provisioners/ansible/ansible_playbook.yml
    amazon-ebs:
    amazon-ebs: PLAY [Jenkins node playbook] ***************************************************
    amazon-ebs:
    amazon-ebs: TASK [Gathering Facts] *********************************************************
    amazon-ebs: ok: [default]
    amazon-ebs:
    amazon-ebs: TASK [include_tasks] ***********************************************************
    amazon-ebs: fatal: [default]: FAILED! => {"reason": "unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>\n\nThe error appears to be in '/home/amedee/repos/packer-ansible-aws-linux/packer/provisioners/ansible/configure_sshd.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Harden sshd configuration\n  ^ here\n"}
    amazon-ebs:
    amazon-ebs: PLAY RECAP *********************************************************************
    amazon-ebs: default                    : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
    amazon-ebs:
==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...

当我把它改成

代码语言:javascript
复制
---
- name: Harden sshd configuration
  lineinfile:
    path: /etc/ssh/sshd_config
    regex: "{{ item.find }}"
    line: "{{ item.replace }}"
  loop:
    - { find: '^(# *)?ChallengeResponseAuthentication (yes|no)', replace: 'ChallengeResponseAuthentication no' }
    - { find: '^(# *)?PasswordAuthentication (yes|no)', replace: 'PasswordAuthentication no' }
    - { find: '^(# *)?PermitRootLogin (yes|no)', replace: 'PermitRootLogin no' }
    - { find: '^(# *)?UsePAM (yes|no)', replace: 'UsePAM no' }
  notify:
    - Restart sshd

  handlers:
    - name: Restart sshd
      service:
        name: sshd
        state: restarted

然后我得到了这个错误:

冲突操作语句: lineinfile、处理程序

代码语言:javascript
复制
==> amazon-ebs: Provisioning with Ansible...
    amazon-ebs: Setting up proxy adapter for Ansible....
==> amazon-ebs: Executing Ansible: ansible-playbook -e packer_build_name="amazon-ebs" -e packer_builder_type=amazon-ebs --ssh-extra-args '-o IdentitiesOnly=yes' -e ansible_ssh_private_key_file=/tmp/ansible-key210397388 -i /tmp/packer-provisioner-ansible927349691 /home/amedee/repos/packer-ansible-aws-linux/packer/provisioners/ansible/ansible_playbook.yml
    amazon-ebs:
    amazon-ebs: PLAY [Jenkins node playbook] ***************************************************
    amazon-ebs:
    amazon-ebs: TASK [Gathering Facts] *********************************************************
    amazon-ebs: ok: [default]
    amazon-ebs:
    amazon-ebs: TASK [include_tasks] ***********************************************************
    amazon-ebs: fatal: [default]: FAILED! => {"reason": "conflicting action statements: lineinfile, handlers\n\nThe error appears to be in '/home/amedee/repos/packer-ansible-aws-linux/packer/provisioners/ansible/configure_sshd.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Harden sshd configuration\n  ^ here\n"}
    amazon-ebs:
    amazon-ebs: PLAY RECAP *********************************************************************
    amazon-ebs: default                    : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
    amazon-ebs:
==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...

对于这份文件:

代码语言:javascript
复制
---
tasks:
  - name: Harden sshd configuration
    lineinfile:
      path: /etc/ssh/sshd_config
      regex: "{{ item.find }}"
      line: "{{ item.replace }}"
    loop:
      - { find: '^(# *)?ChallengeResponseAuthentication (yes|no)', replace: 'ChallengeResponseAuthentication no' }
      - { find: '^(# *)?PasswordAuthentication (yes|no)', replace: 'PasswordAuthentication no' }
      - { find: '^(# *)?PermitRootLogin (yes|no)', replace: 'PermitRootLogin no' }
      - { find: '^(# *)?UsePAM (yes|no)', replace: 'UsePAM no' }
    notify:
      - Restart sshd

handlers:
  - name: Restart sshd
    service:
      name: sshd
      state: restarted

我知道这个错误:

包含的任务文件必须包含任务列表

代码语言:javascript
复制
==> amazon-ebs: Provisioning with Ansible...
    amazon-ebs: Setting up proxy adapter for Ansible....
==> amazon-ebs: Executing Ansible: ansible-playbook -e packer_build_name="amazon-ebs" -e packer_builder_type=amazon-ebs --ssh-extra-args '-o IdentitiesOnly=yes' -e ansible_ssh_private_key_file=/tmp/ansible-key347362703 -i /tmp/packer-provisioner-ansible498794402 /home/amedee/repos/packer-ansible-aws-linux/packer/provisioners/ansible/ansible_playbook.yml
    amazon-ebs:
    amazon-ebs: PLAY [Jenkins node playbook] ***************************************************
    amazon-ebs:
    amazon-ebs: TASK [Gathering Facts] *********************************************************
    amazon-ebs: ok: [default]
    amazon-ebs:
    amazon-ebs: TASK [include_tasks] ***********************************************************
    amazon-ebs: fatal: [default]: FAILED! => {"reason": "included task files must contain a list of tasks"}
    amazon-ebs:
    amazon-ebs: PLAY RECAP *********************************************************************
    amazon-ebs: default                    : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
    amazon-ebs:
==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...

我很确定这是一个令人讨厌的简单语法错误,但我真的需要一些额外的眼睛来寻找它。

EN

回答 1

Stack Overflow用户

发布于 2021-01-13 16:18:24

我摆脱了处理程序,现在起作用了:

代码语言:javascript
复制
---
- name: Harden sshd configuration
  lineinfile:
    path: /etc/ssh/sshd_config
    regex: "{{ item.find }}"
    line: "{{ item.replace }}"
  loop:
    - {find: '^(# *)?ChallengeResponseAuthentication (yes|no)',
       replace: 'ChallengeResponseAuthentication no'}
    - {find: '^(# *)?PasswordAuthentication (yes|no)',
       replace: 'PasswordAuthentication no'}
    - {find: '^(# *)?PermitRootLogin (yes|no)',
       replace: 'PermitRootLogin no'}
    - {find: '^(# *)?UsePAM (yes|no)',
       replace: 'UsePAM no'}

- name: Restart sshd
  service:
    name: sshd
    state: restarted
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65704210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档