PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 6, 2022

[FIXED] How can I define multiple instances in molecule which differ only in name?

 November 06, 2022     ansible, docker, molecule, testing     No comments   

Issue

I've got a molecule.yml which looks a bit like this:

dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: testohpc-compute-0
    image: docker.io/pycontribs/centos:7
    pre_build_image: true
    groups:
      - testohpc_compute
    command: /sbin/init
    tmpfs:
      - /run
      - /tmp
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - name: net1

How can I define another instance, say testohpc-compute-2 which is exactly the same except for name? Do I really need to copy all the definition from -1 again?

Furthermore, if there's a way of reusing an instance definition, can I share it between scenarios?


Solution

You can take advantage of yaml anchor and merge key features. You can find a basic explanation on Learn yaml in Y minute.

In your specific case, here is a possible solution.

platforms:
  - &default_platform
    name: testohpc-compute-0
    image: docker.io/pycontribs/centos:7
    pre_build_image: true
    groups:
      - testohpc_compute
    command: /sbin/init
    tmpfs:
      - /run
      - /tmp
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - name: net1
  - <<: *default_platform
    name: testohpc-compute-2

Note: anchors and merge keys can only be used in the same yaml file. So this will not work between different scenario.



Answered By - Zeitounator
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing