使用 RHEL 角色

  1. 參考 timesync 角色文件的範例,撰寫 timesync.yml 腳本,在 dev 受管主機使用 timesync 角色啟用校時服務,時間伺服器 192.168.122.1,啟用 iburst 參數。
    [deyu1@kvm19 ansible]$ vim timesync.yml
    [deyu1@kvm19 ansible]$ cat timesync.yml
    ---
    - hosts: dev
      vars:
        timesync_ntp_servers:
          - hostname: 192.168.122.1
            iburst: yes
      roles:
        - rhel.system_roles.timesync
    
  2. ansible-playbook 執行 timesync.yml 腳本,輸出 failed=0 表示成功。
    [deyu1@kvm19 ansible]$ ansible-playbook timesync.yml
    
    PLAY [dev] **********************************************************************
    
    TASK [Gathering Facts] **********************************************************
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Set version specific variables] *******
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Populate service facts] ***************
    [WARNING]: Unable to query 'service' tool (1):
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Set variable `timesync_services` with filtered uniq service names] ***
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Check that variable 'timesync_services' is defined] ***
    ok: [kvm11] => {
        "changed": false,
        "msg": "All assertions passed"
    }
    
    TASK [redhat.rhel_system_roles.timesync : Check if only NTP is needed] **********
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Check if single PTP is needed] ********
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Check if both NTP and PTP are needed] ***
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Determine current NTP provider] *******
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Select NTP provider] ******************
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Install chrony] ***********************
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Install ntp] **************************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Install linuxptp] *********************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Gather package facts] *****************
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Run phc_ctl on PTP interface] *********
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Check if PTP interface supports HW timestamping] ***
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate chrony.conf file] ************
    changed: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate chronyd sysconfig file] ******
    changed: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate ntp.conf file] ***************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate ntpd sysconfig file] *********
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate ptp4l.conf file] *************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate ptp4l sysconfig file] ********
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate phc2sys sysconfig file] ******
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Generate timemaster.conf file] ********
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Update network sysconfig file] ********
    changed: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Disable chronyd] **********************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Disable ntpd] *************************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Disable ntpdate] **********************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Disable sntp] *************************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Disable ptp4l] ************************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Disable phc2sys] **********************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Disable timemaster] *******************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Enable chronyd] ***********************
    ok: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Enable ntpd] **************************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Enable ptp4l] *************************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Enable phc2sys] ***********************
    skipping: [kvm11]
    
    TASK [redhat.rhel_system_roles.timesync : Enable timemaster] ********************
    skipping: [kvm11]
    
    RUNNING HANDLER [redhat.rhel_system_roles.timesync : restart chronyd] ***********
    changed: [kvm11]
    
    PLAY RECAP **********************************************************************
    kvm11  : ok=15 changed=4  unreachable=0  failed=0 skipped=23 rescued=0  ignored=0
    
  3. 查詢 dev 主機的時間校時服務的設定,是否依 timesync.yml 腳本配置校時伺服器及參數?
    [deyu1@kvm19 ansible]$ ansible dev -m shell -a "grep ^server /etc/chrony.conf"
    kvm11 | CHANGED | rc=0 >>
    server 192.168.122.1 iburst