81 lines
2.2 KiB
YAML
81 lines
2.2 KiB
YAML
---
|
|
- name: Clear all aliases on hcp1 and hcp2
|
|
hosts: hcp1,hcp2
|
|
become: yes
|
|
|
|
tasks:
|
|
- name: Check current aliases
|
|
shell: alias || echo "No aliases found"
|
|
register: current_aliases
|
|
|
|
- name: Display current aliases
|
|
debug:
|
|
msg: "Current aliases: {{ current_aliases.stdout_lines }}"
|
|
|
|
- name: Clear aliases from /root/.bashrc
|
|
shell: |
|
|
sed -i '/^alias /d' /root/.bashrc
|
|
sed -i '/^alias\t/d' /root/.bashrc
|
|
ignore_errors: yes
|
|
|
|
- name: Clear aliases from /root/.profile
|
|
shell: |
|
|
sed -i '/^alias /d' /root/.profile
|
|
sed -i '/^alias\t/d' /root/.profile
|
|
ignore_errors: yes
|
|
|
|
- name: Clear aliases from /root/.zshrc
|
|
shell: |
|
|
sed -i '/^alias /d' /root/.zshrc
|
|
sed -i '/^alias\t/d' /root/.zshrc
|
|
ignore_errors: yes
|
|
|
|
- name: Clear aliases from /etc/bash.bashrc
|
|
shell: |
|
|
sed -i '/^alias /d' /etc/bash.bashrc
|
|
sed -i '/^alias\t/d' /etc/bash.bashrc
|
|
ignore_errors: yes
|
|
|
|
- name: Clear aliases from /etc/profile
|
|
shell: |
|
|
sed -i '/^alias /d' /etc/profile
|
|
sed -i '/^alias\t/d' /etc/profile
|
|
ignore_errors: yes
|
|
|
|
- name: Find and clear custom alias files
|
|
find:
|
|
paths: ["/root", "/etc", "/home"]
|
|
patterns: ["*.aliases", ".aliases", "aliases"]
|
|
recurse: yes
|
|
register: alias_files
|
|
|
|
- name: Remove found alias files
|
|
file:
|
|
path: "{{ item.path }}"
|
|
state: absent
|
|
loop: "{{ alias_files.files }}"
|
|
when: alias_files.files is defined
|
|
|
|
- name: Clear shell history to remove alias commands
|
|
shell: |
|
|
> /root/.bash_history
|
|
> /root/.zsh_history
|
|
history -c
|
|
ignore_errors: yes
|
|
|
|
- name: Unalias all current aliases
|
|
shell: unalias -a
|
|
ignore_errors: yes
|
|
|
|
- name: Restart shell services
|
|
shell: |
|
|
pkill -f bash || true
|
|
pkill -f zsh || true
|
|
|
|
- name: Test network connectivity after clearing aliases
|
|
shell: ping -c 2 8.8.8.8 || echo "Ping failed"
|
|
register: ping_test
|
|
|
|
- name: Display ping test result
|
|
debug:
|
|
msg: "Ping test: {{ ping_test.stdout_lines }}" |