Answers: <p>I think it should be:</p>
  <pre><code>children:
      docker:
        hosts:
          01-dev:
          02-dev:
  </code></pre>
  <p>(The colon)</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-02-05T22:37:34.970Z
Answers: yes, that fixed it, thanks.
  But why does ansible expect a colon after the hosts? There are no elements as sub-keys. The syntax is quite counter-intuitive
Answers: dfsg76
Answers: CC BY-SA 4.0
Answers: 2021-02-05T14:22:17.880Z
Answers: 2021-02-05T14:22:17.880Z
Answers: Soeren
Body: <p>I'm trying for hours already to run a docker installation on a specific group of hosts.</p>
  <p>This is my hosts.yml</p>
  <pre><code>all:
    hosts:
      01-dev:
        ansible_host: &lt;IP1&gt;
      02-dev:
        ansible_host: &lt;IP2&gt;
      03-dev:
        ansible_host: &lt;IP3&gt;
  
    children:
      docker:
        hosts:
          01-dev
          02-dev
      dev:
        hosts:
          01-dev
          02-dev
          03-dev
  </code></pre>
  <p>This is my site.yml</p>
  <pre><code>
  - name: Configure hosts
    hosts: dev
    tasks:
      - name: Update and upgrade apt packages
        become: true
        apt:
          upgrade: yes
          update_cache: yes
          cache_valid_time: 86400 #One day
      - name: Install needed network manager libs
        become: yes
        ansible.builtin.package:
          name:
            - network-manager
          state: present
      - name: &quot;Configuring eth&quot;
        become: yes
        community.general.nmcli:
          conn_name: &quot;System ens18&quot;
          ifname: ens18
          type: ethernet
          state: present
          autoconnect: yes
          ip4: &quot;{{ansible_host}}/24&quot;
          gw4: &quot;192.168.3.1&quot;
  
    hosts: docker
    become: true
    tasks:
      - name: Install aptitude using apt
        apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
  
      - name: Install required system packages
        apt: name={{ item }} state=latest update_cache=yes
        loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools']
  
      - name: Add Docker GPG apt Key
        apt_key:
          url: https://download.docker.com/linux/ubuntu/gpg
          state: present
  
      - name: Add Docker Repository
        apt_repository:
          repo: deb https://download.docker.com/linux/ubuntu bionic stable
          state: present
  
      - name: Update apt and install docker-ce
        apt: update_cache=yes name=docker-ce state=latest
  
      - name: Install Docker Module for Python
        pip:
          name: docker
  </code></pre>
  <p>Then I run the command <code>ansible-playbook -i hosts.yml site.yml -vvv --ask-become-pass</code> and I get the error that there are no hosts for a group <code>docker</code></p>
  <p>What is wrong with my hosts file?</p>
  
Tags: <docker><ansible><ubuntu>
Title: Ansible hosts group reference does not work
UserDisplayName: dfsg76
ThreadText: # Ansible hosts group reference does not work
  
  (Asked by: username_0 on 2021-02-01)
  
  I'm trying for hours already to run a docker installation on a specific group of hosts.
  
  This is my hosts.yml
  
  ```
  all:
    hosts:
      01-dev:
        ansible_host: <IP1>
      02-dev:
        ansible_host: <IP2>
      03-dev:
        ansible_host: <IP3>
  
    children:
      docker:
        hosts:
          01-dev
          02-dev
      dev:
        hosts:
          01-dev
          02-dev
          03-dev
  
  ```
  
  This is my site.yml
  
  ```
  
  - name: Configure hosts
    hosts: dev
    tasks:
      - name: Update and upgrade apt packages
        become: true
        apt:
          upgrade: yes
          update_cache: yes
          cache_valid_time: 86400 #One day
      - name: Install needed network manager libs
        become: yes
        ansible.builtin.package:
          name:
            - network-manager
          state: present
      - name: "Configuring eth"
        become: yes
        community.general.nmcli:
          conn_name: "System ens18"
          ifname: ens18
          type: ethernet
          state: present
          autoconnect: yes
          ip4: "{{ansible_host}}/24"
          gw4: "192.168.3.1"
  
    hosts: docker
    become: true
    tasks:
      - name: Install aptitude using apt
        apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
  
      - name: Install required system packages
        apt: name={{ item }} state=latest update_cache=yes
        loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools']
  
      - name: Add Docker GPG apt Key
        apt_key:
          url: https://download.docker.com/linux/ubuntu/gpg
          state: present
  
      - name: Add Docker Repository
        apt_repository:
          repo: deb https://download.docker.com/linux/ubuntu bionic stable
          state: present
  
      - name: Update apt and install docker-ce
        apt: update_cache=yes name=docker-ce state=latest
  
      - name: Install Docker Module for Python
        pip:
          name: docker
  
  ```
  
  Then I run the command `ansible-playbook -i hosts.yml site.yml -vvv --ask-become-pass` and I get the error that there are no hosts for a group `docker`
  
  What is wrong with my hosts file?
  
  **Tags:** docker, ansible, ubuntu
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-02-05. Score: 1 | Accepted answer
  
  I think it should be:
  
  ```
  children:
      docker:
        hosts:
          01-dev:
          02-dev:
  
  ```
  
  (The colon)
  
  > **Comments:**
  > **username_0**: yes, that fixed it, thanks. But why does ansible expect a colon after the hosts? There are no elements as sub-keys. The syntax is quite counter-intuitive  
  
  ---
  
  