ansible workstation 配置筆記

  • Post author:
  • 帖子最後修改:2025 年 9 月 29 日
  • Post comments:0評論

Table of Contents

架構

  • Home主機 家目錄設置。
  • WorkStation 被設置主機。
  • 劇本for worstation。

Home 主機 家目錄設置。

				
					vim /etc/hosts
192.168.0.21 workstation.example.com workstation
-------------------------------
vim .vimrc
autocmd Filetype html setlocal ai ts=1 sw=2 et nu cursorcolumn cursorline
autocmd Filetype j2 setlocal ai ts=2 sw=2 et nu cursorcolumn cursorline
autocmd Filetype yaml setlocal ai ts=2 sw=2 et nu cursorcolumn cursorline
mkdir wk_ansible
cd wk_ansible
mkdir mycollections
mkdir roles
vim inventory

[wk]
workstation.example.com
-------------------------------
完全註解ansible.cfg
ansible-config init --disabled > ansible.cfg
-------------------------------
vim ansible.cfg
collections_paths=/home/student/wk_ansible/mycollections
inventory=inventory
remote_user=wk
roles_path=/home/student/wk_ansible/roles
become=True
become_ask_pass=False
become_method=sudo
become_user=root
-------------------------------
ssh-copy-id wk@workstation
				
			

WorkStation 被設置主機。

				
					sudi-i
visudo
vi /etc/sudoers.d/wk
wk        ALL=(ALL)       NOPASSWD: ALL

				
			

劇本for worstation。

  • wk_include.yml
  • yum_repo.yml
  • wk_sethostname.yml
  • 劇本for worstation。

wk_include.yml

				
					vim yum_repo.yml
#-------------------------------#
---
- name: include tasks
  hosts: wk
  vars_files:
    - se_forms.yml
    - /{{ ansible_facts['hostname'] }}/se_edit.yml
  tasks:
    - include_tasks: yum_repo.yml
    - include_tasks: wk_sethostname.yml
    - include_tasks: se_epel.yml
    - include_tasks: se_packages.yml
    - include_tasks: se_service.yml
    - include_tasks: se_firewalld.yml
#    - include_tasks: se_nginx_conf.yml
#    - include_tasks: se_ddclient_conf.yml
#    - include_tasks: se_webcontent.yml
#    - include_tasks: se_certbot.yml

				
			

yum_repo.yml

				
					vim yum_repo.yml
#-------------------------------#
---
- name: BaseOS repository
  ansible.builtin.yum_repository:
    file: rhel9.6
    name: BASE
    description: 9.6 base software
    baseurl: http://192.168.0.223/rhel/rhel-9.6_x86_64/BaseOS/
    enabled: yes
    gpgcheck: no
    state: present
- name: AppStream repository
  ansible.builtin.yum_repository:
    file: rhel9.6
    name: STREAM
    description: 9.6 stream software
    baseurl: http://192.168.0.223/rhel/rhel-9.6_x86_64/AppStream/
    enabled: yes
    gpgcheck: no
    state: present

				
			

發佈留言