# Automate setting fleet outputs to remote\_elasticsearch in kibana.yml

**URL:** <https://discuss.elastic.co/t/automate-setting-fleet-outputs-to-remote-elasticsearch-in-kibana-yml/354953>\
**Category:** Kibana\
**Tags:** fleet\
**Created:** [March 7, 2024, 12:41pm UTC](https://discuss.elastic.co/t/automate-setting-fleet-outputs-to-remote-elasticsearch-in-kibana-yml/354953 "2024-03-07T12:41:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![0lzi](https://avatars.discourse-cdn.com/v4/letter/0/f9ae1b/32.png) [@0lzi](https://discuss.elastic.co/u/0lzi)\
**Post date:** [March 7, 2024, 12:41pm UTC](https://discuss.elastic.co/t/automate-setting-fleet-outputs-to-remote-elasticsearch-in-kibana-yml/354953/1 "2024-03-07T12:41:13Z")

</div>

Hi, Im currently trying to automate kibana setup using ansible.

I can configure the outputs and the fleetServerHosts, but the agents do not come online until i go into the UI to add the service token to the outputs.

current `kibana.yml`

```auto
...
..
.
# Fleet Outputs - Works but needs api/fleet/service_token added as secret                                                                                                                     
xpack.fleet.outputs:                                                                                                                                                                          
  - id: elastic-cluster                                                                                                                                                                       
    name: es-cluster                                                                                                                                                                          
    type: remote_elasticsearch                                                                                                                                                                
    is_default: true                                                                                                                                                                          
    is_default_monitoring: true                                                                                                                                                               
    secrets:                                                                                                                                                                                  
      service_token:                                                                                                                                                                          
        id: "token-1709812465197"                                                                                                                                                             
    hosts:                                                                                                                                                                                    
      - https://es1.example.com:9201                                                                                                                                                
      - https://es2.example.com:9202                                                                                                                                                
      - https://es3.example.com:9203                                                                                                                                                
                                             

xpack.fleet.fleetServerHosts:
  - id: fleet-server
    name: Fleet Server
    is_default: true
    host_urls: [https://fleet.example.com:8220]

```

I am using ansible to get the service token, and i get a response like :

```auto
        "json": {
            "name": "token-1709812465197",
            "value": "AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyLXJlbW90ZS90b2tlbi0xNzA5ODEyNDY1MTk3OmlCNWExV2VrUm1taV9pckw5UUF4VWc"
        },

```

Is there a way in the kibana.yml to specify the service token thats generated without putting the token value in?

---

<div class="post-metadata">

**Author:** ![0lzi](https://avatars.discourse-cdn.com/v4/letter/0/f9ae1b/32.png) [@0lzi](https://discuss.elastic.co/u/0lzi)\
**Post date:** [March 8, 2024, 11:31am UTC](https://discuss.elastic.co/t/automate-setting-fleet-outputs-to-remote-elasticsearch-in-kibana-yml/354953/2 "2024-03-08T11:31:34Z")

</div>

To add to this, If i set these outputs and the fleetServerHosts, the fleet.packages and agent.policies do not seem to be created correctly.

```auto
xpack.fleet.packages:
  - name: fleet_server
    version: latest
  - name: system
    version: latest
  - name: elastic_agent
    version: latest
xpack.fleet.agentPolicies:
  - name: Fleet Server policy
    id: fleet-server-policy
    namespace: default
    package_policies:
      - name: fleet_server-1
        package:
          name: fleet_server
  - name: Agent policy 1
    id: agent-policy-1
    namespace: default
    monitoring_enabled:
      - logs
      - metrics
    package_policies:
      - name: system-1
        id: default-system
        package:
          name: system

xpack.fleet.outputs:
  - id: elastic-cluster
    name: es-cluster 
    type: remote_elasticsearch 
    secrets:
      service_token: "AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyLXJlbW90ZS90b2tlbi0xNzA5ODk3MTgyMTA0Ond6LURUaTFDU2VPR29Uc1JrSkRBQ1E"
    hosts:
      - https://es1.example.com:9201
      - https://es2.example.com:9202
      - https://es3.example.com:9203

xpack.fleet.fleetServerHosts:
  - id: fleet-server
    name: Fleet Server
    is_default: true
    host_urls: [https://fleet.example.com:8220]

```

---

<div class="post-metadata">

**Author:** ![Julia\_Bardi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julia_bardi/32/79463_2.png) [@Julia\_Bardi](https://discuss.elastic.co/u/Julia_Bardi)\
**Post date:** [March 8, 2024, 2:21pm UTC](https://discuss.elastic.co/t/automate-setting-fleet-outputs-to-remote-elasticsearch-in-kibana-yml/354953/3 "2024-03-08T14:21:01Z")

</div>

Hi Oli, welcome to the community!

You can add the service token value directly in the config like this, and it will be stored as a secret in kibana.

```auto
xpack.fleet.outputs:
  - id: elastic-cluster                                                                                                                                                                       
    name: es-cluster                                                                                                                                                                          
    type: remote_elasticsearch                                                                                                                                                                
    is_default: true                                                                                                                                                                          
    is_default_monitoring: true                                                                                                                                                                      
    hosts:                                                                                                                                                                                    
      - https://es1.example.com:9201                                                                                                                                                
      - https://es2.example.com:9202                                                                                                                                                
      - https://es3.example.com:9203 
    secrets:
      service_token: AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyLXJlbW90ZS90b2tlbi0xNzA5ODEyNDY1MTk3OmlCNWExV2VrUm1taV9pckw5UUF4VWc

```

Reference: [[Fleet] Fix preconfigured remote ES outputs with secrets by jillguyonnet · Pull Request #172550 · elastic/kibana · GitHub](https://github.com/elastic/kibana/pull/172550)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 5, 2024, 2:21pm UTC](https://discuss.elastic.co/t/automate-setting-fleet-outputs-to-remote-elasticsearch-in-kibana-yml/354953/4 "2024-04-05T14:21:23Z")

</div>

Closed on April 5, 2024, 2:21pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
