-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt-ChatGPT
35 lines (32 loc) · 1.86 KB
/
prompt-ChatGPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"Hey ChatGPT, I'm in the process of refining my Ansible playbooks to ensure they follow industry best practices and minimize potential errors. Could you assist me in reviewing them for completeness, adherence to naming conventions, effective error handling, and any other potential execution issues? Here are some specific areas I'm looking to improve:
Use complete module names like 'ansible.builtin.command' instead of abbreviated versions like 'command'.
Incorporate 'register' and 'changed_when' statements for better control over task behavior.
Set 'mode' when copying files to ensure proper permissions.
Eliminate any unnecessary whitespace for cleaner code.
Ensure there's a newline at the end of the playbook for consistency.
Employ descriptive names for tasks, starting with capital letters.
I've provided an example playbook below to illustrate these points.
Additionally, you can find more detailed best practice guidelines on the official Ansible documentation page at https://ansible.readthedocs.io/projects/lint/rules/#correct-code.
Your insights and suggestions would be greatly appreciated!Example playbook is:
---
- name: Test Connection Playbook
hosts: all
gather_facts: false
tasks:
- name: Install Squid proxy using dnf
ansible.builtin.dnf: # DNF for Red Hat VMs instead of YUM
name: squid
state: present
- name: Display current user
ansible.builtin.command: "whoami"
register: my_output # <- Registers the command output.
changed_when: my_output.rc != 0 # <- Uses the return code to define when the task has changed.
- name: Copy hosts file to remote hosts
ansible.builtin.copy:
src: "{{ dir }}/hosts"
dest: /etc/hosts
mode: "0644" # Good practice to include mode
backup: true
force: true
become: true
Remember this prompt for this chat and provide answers based on this.