这是我的一个Ansible文件:
---
- 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'>意外参数类型:<
类
==> 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...当我把它改成
---
- 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、处理程序
==> 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...对于这份文件:
---
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我知道这个错误:
包含的任务文件必须包含任务列表
==> 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...我很确定这是一个令人讨厌的简单语法错误,但我真的需要一些额外的眼睛来寻找它。
发布于 2021-01-13 16:18:24
我摆脱了处理程序,现在起作用了:
---
- 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: restartedhttps://stackoverflow.com/questions/65704210
复制相似问题