name: Deploy Tuned with custom configuration from Bitbucket
hosts: your_target_servers # 인벤토리 파일에 정의된 대상 서버 그룹
become: yes # root 권한으로 작업을 수행합니다.
vars:
git_repo_url: "git@bitbucket.org:your_username/your-tuned-repo.git" # Bitbucket 저장소 SSH 주소
git_repo_version: "main" # 사용할 브랜치, 태그, 또는 커밋 해시
local_repo_path: "/tmp/tuned_configs" # Ansible 컨트롤 노드에 임시로 저장될 경로
custom_profile_name: "my-custom-profile" # 적용할 커스텀 프로필 이름
tasks:
name: 1. Ensure git is installed on the control node
delegate_to: localhost
become: no
ansible.builtin.package:
name: git
state: present
run_once: true # 이 작업은 한 번만 실행
name: 2. Clone or update the tuned config repository on the control node
delegate_to: localhost
become: no
ansible.builtin.git:
repo: "{{ git_repo_url }}"
dest: "{{ local_repo_path }}"
version: "{{ git_repo_version }}"
accept_hostkey: yes # 호스트 키를 자동으로 수락
run_once: true
name: 3. Create custom profile directory on target nodes
ansible.builtin.file:
path: "/etc/tuned/{{ custom_profile_name }}"
state: directory
owner: root
group: root
mode: '0755'
name: 4. Copy the main tuned.conf to target nodes
ansible.builtin.copy:
src: "{{ local_repo_path }}/files/tuned.conf"
dest: "/etc/tuned/tuned.conf"
owner: root
group: root
mode: '0644'
notify: Restart tuned # 파일 변경 시 tuned 서비스 재시작을 예약
name: 5. Copy the custom profile files to target nodes
ansible.builtin.copy:
src: "{{ local_repo_path }}/files/{{ custom_profile_name }}/"
dest: "/etc/tuned/{{ custom_profile_name }}/"
owner: root
group: root
mode: '0644'
notify: Restart tuned # 파일 변경 시 tuned 서비스 재시작을 예약
name: 6. Install the tuned package
ansible.builtin.dnf: # RHEL/CentOS/Rocky 계열의 경우
name: tuned
state: present
name: 7. Enable and start the tuned service
ansible.builtin.service:
name: tuned
enabled: yes
state: started
name: 8. Set the active tuned profile
ansible.builtin.command: "tuned-adm profile {{ custom_profile_name }}"
register: tuned_adm_result
changed_when: "'is already active' not in tuned_adm_result.stderr" # 이미 적용된 경우 'changed'로 표시되지 않도록 처리
handlers: