Ansible-playbook "Update Content Views" using variables

Update Content Views

I have a complex set of content views and repositories.
I wanted to use ansible to cycle through the content views and repositories assign the appropriate repositories to the content views.

I tried to loop through each repository, but only the final repository in the loop was added to the content view, any previous repositories are removed using this method.
This is a simplified version of my data and code.

  vars:
    my_contentviews:
      - { name: "cv_GROUPA", composite: false }
      - { name: "cv_GROUPB", composite: false }
      - { name: "cv_GROUPC", composite: false }

my_repository:
  - { name: "EPEL 6 - x86_64" , product: "EPEL 6" ,label: "EPEL_6", content_type: "yum" , content_view: "cv_GROUPA", url: "http://mirrors.kernel.org/fedora-epel/6/x86_64/" }
  - { name: "EPEL 7 - x86_64" , product: "EPEL 7" ,label: "EPEL_7", content_type: "yum" , content_view: "cv_GROUPA", url: "http://mirrors.kernel.org/fedora-epel/7/x86_64/" }
  - { name: "EPEL 8 - x86_64" , product: "EPEL 8" ,label: "EPEL_8", content_type: "yum" , content_view: "cv_GROUPC", url: "http://mirrors.kernel.org/fedora-epel/8/Everything/x86_64/" }


- name: "Update Content Views"
  theforeman.foreman.content_view:
    server_url: "{{ my_server_url  }}"
    username: "{{  my_userid }}"
    password: "{{ my_secret }}"
    organization: "{{ my_org }}"
    name: "{{ item.content_view }}"
    repositories:
      - name: "{{ item.name }}" 
        product: "{{ item.product }}"         
  with_items:
    - "{{ my_repository }}"

Any idea how I should do this?

Hi,

when you call theforeman.foreman.content_view, you need to pass all repositories in one run, as otherwise each loop iteration will modify the CV and only set it to contain the one repository of that loop iteration (as you see now).

Your intent is to have a list of repositories, and then have each of them also indicate which CV it should go into? That might be a bit complicated to express with Ansible.

1 Like