almond
October 8, 2021, 6:40am
#1
Problem:
Error while creating a docker repository through playbook
Expected outcome:
Docker repository should be added
Foreman and Proxy versions:
2.2.5
Foreman and Proxy plugin versions:
Distribution and version:
RHEL 7
Other relevant data:
I am getting error while creating a alpine docker repository using ansible playbook. Yum repository is working fine. Here’s the yml file I tried.
- name: "Create repository"
theforeman.foreman.repository:
username: "admin"
password: "admin"
server_url: "https:myworld.com"
name: "dockerproduct1"
state: present
content_type: "docker"
organization: "Test Organization"
docker_upstream_name: "alpine"
url: "https://registry-1.docker.io/"
mirror_on_sync: true
download_policy: immediate
Anything I’m doing wrong here or any fields missing?
evgeni
October 8, 2021, 6:46am
#2
It’s hard to say without the error you’re getting
almond
October 8, 2021, 6:47am
#3
Oh sheesh. My bad.
fatal: [121.234.44.54]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to be in '/root/foreman_playbooks/create_docker_repository.yml': line 17, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: \"Create repository\"\n ^ here\n"}
@evgeni
evgeni
October 8, 2021, 6:48am
#4
There is no {{ item }}
in the YAML you posted. Can you show us the real playbook?
But this looks like a general Ansible/YAML syntax error, unrelated to the Docker repository.
almond
October 8, 2021, 6:51am
#5
Tried out a few things and still facing the same error. Here’s the full preview of the playbook
---
- hosts: foreman
vars_prompt:
- name: "Product"
prompt: "Which Product Do you want to install?"
private: "No"
tasks:
- name: "Create product with a sync plan"
theforeman.foreman.product:
username: "admin"
password: "admin"
server_url: "https://myworld.com/"
name: "{{ Product }}"
organization: "Test Organization"
state: present
- name: "Create repository"
theforeman.foreman.repository:
username: "admin"
password: "admin"
server_url: "https://myworld.com/"
name: "{{ item }}"
state: present
content_type: "docker"
product: "{{ Product }}"
organization: "Test Organization"
docker_upstream_name: "alpine"
url: "https://registry-1.docker.io/"
mirror_on_sync: true
download_policy: immediate
evgeni
October 8, 2021, 6:53am
#6
almond:
name: "{{ item }}"
You never define item
(and there is no with_items
or loop
on that task…)
In your original post, you had name: "dockerproduct1"
, which is valid.
almond
October 8, 2021, 6:54am
#7
Have you got any sample/example for creating a docker repository using playbook?
evgeni
October 8, 2021, 6:54am
#8
The one in your first post looks valid to me?
evgeni
October 8, 2021, 6:58am
#9
Here is one from our integration tests:
- name: "Create container repository"
theforeman.foreman.repository:
username: "admin"
password: "changeme"
server_url: "https://foreman.example.com"
organization: "Test Organization"
name: "Test Docker Repository"
product: "Test Product"
content_type: "docker"
url: "https://docker.io"
docker_upstream_name: "busybox"
docker_tags_whitelist:
- latest
almond
October 8, 2021, 7:05am
#11
@evgeni That worked. How can we sync the repository along with this playbook?
evgeni
October 8, 2021, 7:07am
#12
almond
October 8, 2021, 10:20am
#14
@evgeni getting too many requests error when I remove tag limit
evgeni
October 8, 2021, 10:27am
#15
Yeah, Docker Hub limits requests these days. I think you can set upstream_username
and upstream_password
to authenticate with your paid account.