# Conflicting action statements: set\_fact, add\_host

**URL:** <https://forum.ansible.com/t/conflicting-action-statements-set-fact-add-host/39200>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [December 17, 2024, 10:04am UTC](https://forum.ansible.com/t/conflicting-action-statements-set-fact-add-host/39200 "2024-12-17T10:04:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robi1a](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/robi1a/32/2737_2.png) [@robi1a](https://forum.ansible.com/u/robi1a)\
**Post date:** [December 17, 2024, 10:04am UTC](https://forum.ansible.com/t/conflicting-action-statements-set-fact-add-host/39200/1 "2024-12-17T10:04:12Z")

</div>

Hello

I retrieve all hosts from the monitoring system to var host\_list.  
Than I loop through host\_list and want to build an inventory with add\_host: by passing through some filters. Finally, the build inventory will be taken to install software. But, I receive the following error:

```auto
Vault password: 

PLAY [Update all CMK agents] ***************************************************

TASK [get host list from CMK] **************************************************
ERROR! conflicting action statements: set_fact, add_host

The error appears to be in '/runner/project/import_cmk_get_list.yaml': line 67, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  # ############################################# WindowsServerDomain ###################################
  - name: Add host to group 'WindowsServerDomain'
    ^ here

```

I want to use set\_fact: to the the var Kunde for each item of the loop for a later use to the the appropriate credentials. The playbook is running in AWX.  
I have no idea why this happens. I googled a long time but find no solution.  
Hope someone can give me hint or the solution.  
Following the piece of the playbook around the error.

```auto
---
  # ################################################################################
  # create list of selected hosts and build inventory
  # ################################################################################
  - name: get host list from CMK
    uri:
      url: "{{ cmk_rest_api_url }}/domain-types/host_config/collections/all?effective_attributes=true"
      method: GET
      headers:
         Authorization: "Bearer {{ cmk_user }} {{ cmk_secret }}"
         Accept: 'application/json'
      force_basic_auth: yes
      status_code: 200,404
    register: host_list

  # ############################################# Linux ###################################
  - name: Add host to group 'Linux'
    with_items: "{{ host_list.json.value }}" 
    loop_control:
      label: "Name: {{ item.id }},
              OS: {{ item.extensions.effective_attributes.tag_Betriebssystem | default('-') }},
              State: {{ item.extensions.effective_attributes.tag_criticality }}"
    when: 
      - do_Linux == 'Yes'
      - item.extensions.effective_attributes.tag_Betriebssystem | default('-') == 'Linux' 
      - item.extensions.effective_attributes.tag_AgentType == 'Agent' 
      - item.extensions.effective_attributes.tag_Systemtyp != 'IoT' 
      - ( (item.extensions.effective_attributes.tag_criticality == 'test' and crit_Test == 'Yes') 
         or (item.extensions.effective_attributes.tag_criticality == 'prod' and crit_Prod == 'Yes') 
         or (item.extensions.effective_attributes.tag_criticality == 'critical' and crit_BusinessCrit == 'Yes')
        )
      - ( (item.extensions.effective_attributes.tag_Kunde == 'inseo' and cust_INSEO == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'cdhw' and cust_DHW == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'ceizo' and cust_EIZO == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'ckru' and cust_KRUCH == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'cDK' and cust_DONAUK == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'cted' and cust_TEDALOS == 'Yes') 
        )
    add_host:
      hostname: '{{ item.id }}'
      groups: Linux
      ansible_host: '{{ item.extensions.attributes.ipaddress }}'
      ansible_port: 22
      become: yes
      become_method: sudo
        #ansible_ssh_user: "{{ inseo_ansible_user }}"
        #ansible_ssh_password: "{{ inseo_ansible_pw }}"
      tag_criticality: '{{ item.extensions.effective_attributes.tag_criticality }}'

  # ############################################# WindowsServerDomain ###################################
  - name: Add host to group 'WindowsServerDomain' 
    with_items: "{{ host_list.json.value }}" 
    loop_control:
      label: "Name: {{ item.id }},
              OS: {{ item.extensions.effective_attributes.tag_Betriebssystem | default('-') }},
              State: {{ item.extensions.effective_attributes.tag_criticality }}"
    when: 
      - do_WindowsServer == 'Yes'
      - item.extensions.effective_attributes.tag_Betriebssystem | default('-') == 'WindowsServer'
      - item.extensions.effective_attributes.tag_AgentType == 'Agent' 
      - item.extensions.effective_attributes.tag_Systemtyp != 'IoT' 
      - ( (item.extensions.effective_attributes.tag_criticality == 'test' and crit_Test == 'Yes') 
         or (item.extensions.effective_attributes.tag_criticality == 'prod' and crit_Prod == 'Yes') 
         or (item.extensions.effective_attributes.tag_criticality == 'critical' and crit_BusinessCrit == 'Yes')
        )
      - ( (item.extensions.effective_attributes.tag_Kunde == 'inseo' and cust_INSEO == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'cdhw' and cust_DHW == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'ceizo' and cust_EIZO == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'ckru' and cust_KRUCH == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'cDK' and cust_DONAUK == 'Yes') 
         or (item.extensions.effective_attributes.tag_Kunde == 'cted' and cust_TEDALOS == 'Yes') 
        )
        #- item.extensions.effective_attributes.tag_ansible_login == 'Domain'
    set_fact:
      Kunde: "{{ item.extensions.effective_attributes.tag_Kunde }}"
    add_host:
      hostname: '{{ item.id }}'
      groups: WindowsServerDomain
      ansible_host: '{{ item.extensions.attributes.ipaddress }}'
      ansible_connection: winrm
      ansible_port: 5985
      ansible_winrm_transport: kerberos
      ansible_user: "{{ cred[Kunde]['user'] }}"
      ansible_password: "{{ cred[Kunde]['pw'] }}"
      tag_criticality: '{{ item.extensions.effective_attributes.tag_criticality }}'

```

regards Robi

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [December 17, 2024, 11:31am UTC](https://forum.ansible.com/t/conflicting-action-statements-set-fact-add-host/39200/2 "2024-12-17T11:31:23Z")

</div>

> [@robi1a](#):
>
> ```auto
> ...
> set_fact:
> Kunde: "{{ item.extensions.effective_attributes.tag_Kunde }}"
> add_host:
> hostname: '{{ item.id }}'
> groups: WindowsServerDomain
> ansible_host: '{{ item.extensions.attributes.ipaddress }}'
> ansible_connection: winrm
> ansible_port: 5985
> ansible_winrm_transport: kerberos
> ansible_user: "{{ cred[Kunde]['user'] }}"
> ansible_password: "{{ cred[Kunde]['pw'] }}"
> tag_criticality: '{{ item.extensions.effective_attributes.tag_criticality }}'
> 
> ```

This is improper. You can’t call `set_facts` and `add_host` in the same task.

P.S. You probably want to use `vars:` instead of `set_facts` here.
