初始化角色 apache

  1. 建立 roles 目錄。
    [deyu1@kvm19 ansible]$ mkdir roles/
    
  2. 查看 ansible.cfg 配置檔的 roles_path,是否已設定 /home/deyu1/ansible/roles 目錄。
    [deyu1@kvm19 ansible]$ vim ansible.cfg 
    [deyu1@kvm19 ansible]$ grep ^roles_path ansible.cfg 
    roles_path    = /home/deyu1/ansible/roles
    
  3. 進入 roles 目錄。
    [deyu1@kvm19 ansible]$ cd roles/
    [deyu1@kvm19 roles]$ pwd
    /home/deyu1/ansible/roles
    
  4. ansible-galaxy 初使化 apache 角色。
    [deyu1@kvm19 roles]$ ansible-galaxy init apache
    - apache was created successfully
    
  5. 查看 apache 目錄,已建立角色需要的目錄及檔案。
    [deyu1@kvm19 roles]$ tree apache/
    apache/
    ├── defaults
    │   └── main.yml
    ├── files
    ├── handlers
    │   └── main.yml
    ├── meta
    │   └── main.yml
    ├── README.md
    ├── tasks
    │   └── main.yml
    ├── templates
    ├── tests
    │   ├── inventory
    │   └── test.yml
    └── vars
        └── main.yml
    
    8 directories, 8 files
    
  6. 回到 ansible 目錄,查看角色,列出 apache 角色。
    [deyu1@kvm19 ansible]$ cd ..
    [deyu1@kvm19 ansible]$ ansible-galaxy list
    # /home/deyu1/ansible/roles
    - apache, (unknown version)