- hosts: ok
  remote_user: ec2-user
  #gather_facts: No 
  become: yes  #表示是否允许用户切换
  become_method: sudo  #表示切换用户的方式，有su/sudo/pbrun等方式，默认是sudo方式
  become_user: root  #表示要切换到哪个用户，即目标用户
  tasks:
    - name: Register NodeExport To Consul
      uri:
        url: http://10.66.2.152:8500/v1/agent/service/register
        method: PUT
        body: "{\"id\":\"{{ ansible_hostname }}\",\"name\":\"{{ ansible_hostname }}\",\"address\":\"{{ ansible_default_ipv4.address }}\",\"port\":9100,\"tags\":[\"hosts-node\"],\"checks\":[{\"http\":\"http://{{ ansible_default_ipv4.address }}:9100/metrics\",\"interval\":\"15s\"}]}"
        body_format: json
        headers:
          Content-Type: "application/json"
    - name: Register ProcessExport To Consul
      uri:
        url: http://10.66.2.152:8500/v1/agent/service/register
        method: PUT
        body: "{\"id\":\"{{ ansible_hostname }}-process\",\"name\":\"{{ ansible_hostname }}\",\"address\":\"{{ ansible_default_ipv4.address }}\",\"port\":9256,\"tags\":[\"hosts-process\"],\"checks\":[{\"http\":\"http://{{ ansible_default_ipv4.address }}:9256/metrics\",\"interval\":\"15s\"}]}"
        body_format: json
        headers:
          Content-Type: "application/json"
