0

I have a playbook and only want to run this play on the first master node. I tried moving the list into the role but did not see to work. Thanks for your help!

## master node only changes
- name: Deploy change kubernetes Master
  remote_user: tyboard
  become: true
  roles:
  - role: gd.kubernetes.master.role
    files_location: ../files
  delegate_to: "{{ groups['masters'][0] }}" 

ERROR! 'delegate_to' is not a valid attribute for a Play

The error appears to be in '/mnt/win/kubernetes.playbook/deploy-kubernetes.yml': line 11, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

master node only changes

  • name: Deploy change kubernetes Master ^ here
TyBoard
  • 1
  • 3

1 Answers1

1

In one playbook, create a new group with this host in the first play and use it in the second play. For example,

shell> cat playbook.yml
- name: Create group with masters.0
  host: localhost
  gather_facts: false
  tasks:
    - add_host:
        name: "{{ groups.masters.0 }}"
        groups: k8s_master_0

- name: Deploy change kubernetes Master
  hosts: k8s_master_0
  remote_user: tyboard
  become: true
  roles:
    - role: gd.kubernetes.master.role
      files_location: ../files

(not tested)


  • Fix the role name

  • If files_location is a variable which shall be used in the role's scope put it into the vars. For example

  roles:
    - role: gd.kubernetes.master.role
      vars:
        files_location: ../files
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63