Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible code bot recommendations #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,3 @@ task_name_prefix: "{stem} | "

# Limit the depth of the nested blocks:
# max_block_depth: 20
...
5 changes: 2 additions & 3 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ rules:
level: error
# Allow only YAML 1.2 booleans https://redhat-cop.github.io/automation-good-practices/#_yaml_and_jinja2_syntax
allowed-values:
- 'true'
- 'false'
...
- "true"
- "false"
1 change: 0 additions & 1 deletion collections/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ collections:
type: git
source: https://github.com/djdanielsson/ansible-esxi.git
- name: redhat.satellite_operations
...
5 changes: 3 additions & 2 deletions inventory/esxi.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
plugin: community.esxi.esxi_inventory
hostname: '192.168.1.229'
username: 'root'
hostname: 192.168.1.229
username: root
group_by:
- guestfamily
- guestid
Expand Down
1 change: 0 additions & 1 deletion playbooks/deploy_kasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
- name: Run kasm role
ansible.builtin.include_role:
name: kasm
...
7 changes: 3 additions & 4 deletions playbooks/deploy_portainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
image: portainer/portainer-ce:latest
state: started
restart: true
restart_policy: "always"
restart_policy: always
ports:
- "8000:8000"
- "9443:9443"
- 8000:8000
- 9443:9443
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
...
4 changes: 1 addition & 3 deletions playbooks/deploy_terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
- name: Terraform
hosts: all
gather_facts: true
vars_files:
"../vault.yml"
vars_files: ../vault.yml
tasks:
- name: Run terraform role
ansible.builtin.include_role:
name: terraform
...
1 change: 0 additions & 1 deletion playbooks/deploy_vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
- name: Run vault role
ansible.builtin.include_role:
name: vault
...
7 changes: 3 additions & 4 deletions playbooks/download_qcow2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
- name: Download_qcow2
hosts: all
gather_facts: true
vars_files:
"../vault.yml"
vars_files: ../vault.yml
tasks:
- name: Stat
ansible.builtin.stat:
path: "{{ setup_down_dest_dir }}{% if (rhel_version | int) >= 9 %}rhel-baseos-{{ rhel_version }}-{{ arch }}-kvm.qcow2 {% else %} rhel-{{ rhel_version }}-{{ arch }}-kvm.qcow2{% endif %}"
path: "{{ setup_down_dest_dir }}{% if (rhel_version | int) >= 9 %}rhel-baseos-{{ rhel_version }}-{{ arch }}-kvm.qcow2 {% else %} rhel-{{ rhel_version }}-{{
arch }}-kvm.qcow2{% endif %}"
register: r_qcow2
vars:
rhel_version: 8.7
Expand All @@ -18,4 +18,3 @@
ansible.builtin.include_role:
name: download_qcow2
when: not r_qcow2['stat']['exists']
...
1 change: 0 additions & 1 deletion playbooks/install_docker_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
- name: Run Docker Ubuntu role
ansible.builtin.include_role:
name: docker_ubuntu
...
35 changes: 17 additions & 18 deletions playbooks/install_satellite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
satellite_installer_scenario: satellite
satellite_installer_package: satellite
satellite_installer_options:
- '--foreman-initial-organization "lab"'
- '--foreman-initial-location "home"'
- '--foreman-initial-admin-password Password1234!'
- '--foreman-proxy-dns true'
- '--foreman-proxy-dns-managed true'
- '--foreman-proxy-dns-interface eth0'
- '--foreman-proxy-dns-zone lab.danielsson.us.com'
- '--foreman-proxy-dns-reverse 1.168.192.in-addr.arpa'
- '--foreman-proxy-dhcp true'
- '--foreman-proxy-dhcp-managed true'
- '--foreman-proxy-dhcp-interface eth0'
- --foreman-initial-organization "lab"
- --foreman-initial-location "home"
- --foreman-initial-admin-password Password1234!
- --foreman-proxy-dns true
- --foreman-proxy-dns-managed true
- --foreman-proxy-dns-interface eth0
- --foreman-proxy-dns-zone lab.danielsson.us.com
- --foreman-proxy-dns-reverse 1.168.192.in-addr.arpa
- --foreman-proxy-dhcp true
- --foreman-proxy-dhcp-managed true
- --foreman-proxy-dhcp-interface eth0
# - '--foreman-proxy-dhcp-additional-interfaces eth1'
# - '--foreman-proxy-dhcp-additional-interfaces eth2'
- '--foreman-proxy-dhcp-range "192.168.1.100 192.168.1.150"'
- '--foreman-proxy-dhcp-gateway 192.168.1.1'
- '--foreman-proxy-dhcp-nameservers 192.168.1.37'
- '--foreman-proxy-tftp true'
- '--foreman-proxy-tftp-managed true'
- '--foreman-proxy-tftp-servername 192.168.1.37'
...
- --foreman-proxy-dhcp-range "192.168.1.100 192.168.1.150"
- --foreman-proxy-dhcp-gateway 192.168.1.1
- --foreman-proxy-dhcp-nameservers 192.168.1.37
- --foreman-proxy-tftp true
- --foreman-proxy-tftp-managed true
- --foreman-proxy-tftp-servername 192.168.1.37
1 change: 0 additions & 1 deletion playbooks/revert_aap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
- vm_name: aapdb
- vm_name: sso
- vm_name: service_catalog
...
1 change: 0 additions & 1 deletion roles/docker_ubuntu/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: whoami
...
15 changes: 6 additions & 9 deletions roles/docker_ubuntu/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ galaxy_info:
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
...
5 changes: 2 additions & 3 deletions roles/docker_ubuntu/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
state: directory
owner: root
group: root
mode: '0755'
mode: "0755"

- name: One way to avoid apt_key once it is removed from your distro
block:
Expand All @@ -38,7 +38,7 @@

- name: Add docker repo
ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
repo: deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
filename: docker
update_cache: false
state: present
Expand Down Expand Up @@ -72,4 +72,3 @@

- name: Flush handlers
ansible.builtin.meta: flush_handlers
...
1 change: 0 additions & 1 deletion roles/docker_ubuntu/tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
remote_user: root
roles:
- docker_ubuntu
...
1 change: 0 additions & 1 deletion roles/download_qcow2/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
rhel_version: 8.8
arch: x86_64 # or aarch64
setup_down_dest_dir: /tmp/
...
15 changes: 6 additions & 9 deletions roles/download_qcow2/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ galaxy_info:
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
...
5 changes: 2 additions & 3 deletions roles/download_qcow2/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
method: GET
return_content: true
headers:
Authorization: "Bearer {{ __r_login.json.access_token }}"
Authorization: Bearer {{ __r_login.json.access_token }}
register: __r_images_output

- name: Simplify the list of possible downloads
Expand All @@ -29,7 +29,6 @@
url: "{{ item.downloadHref }}"
dest: "{{ setup_down_dest_dir }}/{{ item.filename }}"
headers:
Authorization: "Bearer {{ __r_login.json.access_token }}"
Authorization: Bearer {{ __r_login.json.access_token }}
when: image_name is match(item.filename)
loop: "{{ __cf_images }}"
...
1 change: 0 additions & 1 deletion roles/download_qcow2/tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
remote_user: root
roles:
- download_qcow2
...
1 change: 0 additions & 1 deletion roles/download_qcow2/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
login_url: https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
image_url: https://api.access.redhat.com/management/v1/images/rhel/{{ rhel_version }}/x86_64
image_name: "{% if (rhel_version | int) >= 9 %}rhel-baseos-{{ rhel_version }}-{{ arch }}-kvm.qcow2{% else %}rhel-{{ rhel_version }}-{{ arch }}-kvm.qcow2{% endif %}"
...
1 change: 0 additions & 1 deletion roles/esxi_snapshot_rollback/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ get_snapshot_by_name: false
get_last_snapshot: false
r_vm_snapshots_first: false
power_back_on: true
...
15 changes: 6 additions & 9 deletions roles/esxi_snapshot_rollback/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ galaxy_info:
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
...
22 changes: 13 additions & 9 deletions roles/esxi_snapshot_rollback/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

- name: Create dictionary
ansible.builtin.set_fact:
vm_ids: "{{ vm_ids | default({}) | combine({((item | split(':'))[0]): ((item | split(':'))[1])}) }}"
vm_ids: "{{ vm_ids | default({}) | combine({((item | split(':'))[0]): ((item | split(':'))[1])}) }}"
loop: "{{ __new_lines }}"
vars:
__new_lines: "{{ r_vm_ids.stdout | split('\n') }}"
Expand All @@ -28,25 +28,28 @@
# verbosity: 2

- name: Get vm ids
ansible.builtin.shell: "vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i 'Snapshot Name|Snapshot Id' | awk '{ print $3 }'"
ansible.builtin.shell: vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i 'Snapshot Name|Snapshot Id' | awk '{ print $3 }'
changed_when: false
register: r_vm_snapshots_all
when: get_all_snapshots | default(false)

- name: Get snapshot by name
ansible.builtin.shell: "vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i -A 1 '{{ snapshot_name }}' | cut -d ':' -f 2 | grep -v '\\-\\-' | awk '{ print $1 }' | tail -1"
ansible.builtin.shell: vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i -A 1 '{{ snapshot_name }}' | cut -d ':' -f 2 | grep -v '\-\-' | awk '{ print $1
}' | tail -1
changed_when: false
register: r_vm_snapshots_name
when: get_snapshot_by_name | default(false)

- name: Get last snapshot
ansible.builtin.shell: "vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i -A 1 'Snapshot Name' | cut -d ':' -f 2 | grep -v '\\-\\-' | awk '{ print $1 }' | tail -1"
ansible.builtin.shell: vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i -A 1 'Snapshot Name' | cut -d ':' -f 2 | grep -v '\-\-' | awk '{ print $1 }' |
tail -1
changed_when: false
register: r_vm_snapshots_last
when: get_last_snapshot | default(false)

- name: Get first snapshot
ansible.builtin.shell: "vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i -A 1 'Snapshot Name' | cut -d ':' -f 2 | grep -v '\\-\\-' | awk '{ print $1 }' | head -2 | tail -1"
ansible.builtin.shell: vim-cmd vmsvc/snapshot.get {{ vm_ids[vm_name] }} | grep -i -A 1 'Snapshot Name' | cut -d ':' -f 2 | grep -v '\-\-' | awk '{ print $1 }' |
head -2 | tail -1
changed_when: false
register: r_vm_snapshots_first
when: get_first_snapshot | default(false)
Expand All @@ -56,15 +59,17 @@
msg: "{{ vm_snapshot }}"
# verbosity: 2
vars:
vm_snapshot: "{% if get_all_snapshots %}{{ r_vm_snapshots_all }}{% elif get_snapshot_by_name %}{{ r_vm_snapshots_name }}{% elif get_last_snapshot %}{{ r_vm_snapshots_last }}{% elif r_vm_snapshots_first %}{{ r_vm_snapshots_first }}{% else %}'error'{% endif %}"
vm_snapshot: "{% if get_all_snapshots %}{{ r_vm_snapshots_all }}{% elif get_snapshot_by_name %}{{ r_vm_snapshots_name }}{% elif get_last_snapshot %}{{ r_vm_snapshots_last
}}{% elif r_vm_snapshots_first %}{{ r_vm_snapshots_first }}{% else %}'error'{% endif %}"

- name: Revert to snapshot {{ r_vm_snapshots }}
ansible.builtin.shell: "vim-cmd vmsvc/snapshot.revert {{ vm_ids[vm_name] }} {{ vm_snapshot.stdout }} suppressPowerOn"
ansible.builtin.shell: vim-cmd vmsvc/snapshot.revert {{ vm_ids[vm_name] }} {{ vm_snapshot.stdout }} suppressPowerOn
changed_when: true
register: r_revert_output
when: revert_2_snapshot | default(false)
vars:
vm_snapshot: "{% if get_all_snapshots %}{{ r_vm_snapshots_all }}{% elif get_snapshot_by_name %}{{ r_vm_snapshots_name }}{% elif get_last_snapshot %}{{ r_vm_snapshots_last }}{% elif r_vm_snapshots_first %}{{ r_vm_snapshots_first }}{% else %}'error'{% endif %}"
vm_snapshot: "{% if get_all_snapshots %}{{ r_vm_snapshots_all }}{% elif get_snapshot_by_name %}{{ r_vm_snapshots_name }}{% elif get_last_snapshot %}{{ r_vm_snapshots_last
}}{% elif r_vm_snapshots_first %}{{ r_vm_snapshots_first }}{% else %}'error'{% endif %}"

- name: Printout status
ansible.builtin.debug:
Expand All @@ -75,4 +80,3 @@
ansible.builtin.shell: vim-cmd vmsvc/power.on {{ vm_ids[vm_name] }}
changed_when: true
when: power_back_on
...
1 change: 0 additions & 1 deletion roles/esxi_snapshot_rollback/tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
remote_user: root
roles:
- esxi_snapshot_rollback
...
5 changes: 2 additions & 3 deletions roles/kasm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
# defaults file for kasm
kasm_admin_pass: "Password1234!"
kasm_user_pass: "Password1234!"
...
kasm_admin_pass: Password1234!
kasm_user_pass: Password1234!
1 change: 0 additions & 1 deletion roles/kasm/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
ansible.builtin.file:
path: "{{ tmp_dir.path }}"
state: absent
...
15 changes: 6 additions & 9 deletions roles/kasm/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ galaxy_info:
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
...
3 changes: 1 addition & 2 deletions roles/kasm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- name: Download and unpack tar.gz file
ansible.builtin.unarchive:
src: "https://kasm-static-content.s3.amazonaws.com/kasm_release_1.15.0.06fdc8.tar.gz"
src: https://kasm-static-content.s3.amazonaws.com/kasm_release_1.15.0.06fdc8.tar.gz
dest: "{{ tmp_dir.path }}"
remote_src: true
mode: "0755"
Expand All @@ -20,4 +20,3 @@
# no_log: true
changed_when: true
become: true
...
1 change: 0 additions & 1 deletion roles/kasm/tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
remote_user: root
roles:
- kasm
...
Loading
Loading