这是我的 Ansible 任务
- name: no need to import it.
ansible.builtin.uri:
url: >
https://{{ vertex_region }}-aiplatform.googleapis.com/v1/projects/{{ project }}/locations/{{ vertex_region }}/datasets/{{ dataset_id }}/dataItems
method: GET
headers:
Content-Type: "application/json"
Authorization: Bearer "{{ gcloud_auth }}"
register: images
Run Code Online (Sandbox Code Playgroud)
在检查 Ansible lint 时,它会溢出:
行太长(151 > 120 个字符)(行长度)
该错误是针对url任务的参数的。我已经习惯>了分解url,不知道如何进一步减少它以适应 Ansible lint 给出的行约束?
我已经知道,如果你和他们之间有很长的条件,你可以使用列表将它们分成多行.
尽管如此,我不知道你们之间有OR的情况有任何解决方案.
现实生活中的实际例子:
when: ansible_user_dir is not defined or ansible_python is not defined or ansible_processor_vcpus is not defined
Run Code Online (Sandbox Code Playgroud)
这条线难看且难以阅读,显然不适合79列.
我们如何重写它以使其更容易阅读?
我终于开始使用 Ansible Lint 来确保我是最新的并且没有遗漏任何东西,我发现它报告了一个奇怪的错误/通知。当我dnf用来安装软件包时,我一直在使用state: latest它作为系统引导过程,我可能会在同一个实例上多次运行,特别是在开发过程中。我总是希望在这种情况下安装最新的软件包,但是 Ansible Lint 报告:
Package installs should not use latest
Run Code Online (Sandbox Code Playgroud)
虽然我确信在我的用例中我没问题,但这仅仅是因为为了“幂等性”,人们通常不想要这种行为吗?还是另有原因?如果他们总是要报告这个,那为什么还要提供latest状态选项?
在Ansible角色中,我这样做:
- name: update trusted ca
shell: "{{ in_ca_dict[ansible_os_family]['update']['shell'] }}"
Run Code Online (Sandbox Code Playgroud)
与:
package_name: ca-certificates
RedHat:
path:
6: /usr/local/share/ca-certificates
7: /etc/pki/ca-trust/source/anchors
update:
shell: /bin/update-ca-trust
Debian:
path: /usr/local/share/ca-certificates
update:
shell: /usr/sbin/update-ca-certificates
cache: "no"
Run Code Online (Sandbox Code Playgroud)
但ansible-lint通过告诉我molecule:
[ANSIBLE0013] Use shell only when shell functionality is required
Run Code Online (Sandbox Code Playgroud)
何时需要外壳功能,何时不要求外壳功能?
应该如何选择替代方法,我的代码对我来说似乎很好。