Giter Club home page Giter Club logo

Comments (11)

sky-joker avatar sky-joker commented on August 16, 2024 1

@antivirtel

Thanks for making time to check that.
By using docker, I could confirm the same error.

ok.
I agree that moves the task files to the tasks directory to fix the issue.
I'm probably going to take some time to make a patch for fixing the error.

from molecule-vmware.

sky-joker avatar sky-joker commented on August 16, 2024 1

Thank you for checking driver behavior.

About Migration

You can be migrated to copy molecule.yml from the old molecule scenario directory to a new one after generating the new scenario.
I made a sample script to migrate.
Please refer to:

https://gist.github.com/sky-joker/a5e989367cb3e559dc3bc94357018110

How to use the above tool

Please execute in the same hierarchy of the roles directory.

$ ls
migration_molecule_vmware.py  roles  venv
$ ./migration_molecule_vmware.py

If you will not specify the delete option, molecule backup directry will be created.

$ ls roles/sample/
molecule  molecule_back  tasks
$ find roles/sample/molecule -type f
roles/sample/molecule/default/molecule.yml
roles/sample/molecule/default/tasks/main.yml
roles/sample/molecule/default/tasks/create_linux_instance.yml
roles/sample/molecule/default/tasks/create_windows_instance.yml
roles/sample/molecule/default/handlers/main.yml
roles/sample/molecule/default/INSTALL.rst
roles/sample/molecule/default/converge.yml
roles/sample/molecule/default/create.yml
roles/sample/molecule/default/destroy.yml
roles/sample/molecule/default/verify.yml

$ find roles/sample/molecule_back/ -type f
roles/sample/molecule_back/default/molecule.yml
roles/sample/molecule_back/default/tasks/main.yml
roles/sample/molecule_back/default/INSTALL.rst
roles/sample/molecule_back/default/converge.yml
roles/sample/molecule_back/default/create.yml
roles/sample/molecule_back/default/create_linux_instance.yml
roles/sample/molecule_back/default/create_windows_instance.yml
roles/sample/molecule_back/default/destroy.yml
roles/sample/molecule_back/default/verify.yml
$ openssl md5 roles/sample/molecule_back/default/molecule.yml
MD5(roles/sample/molecule_back/default/molecule.yml)= 0feb8fd208ffe4c80d97040b97cf5108
$ openssl md5 roles/sample/molecule/default/molecule.yml
MD5(roles/sample/molecule/default/molecule.yml)= 0feb8fd208ffe4c80d97040b97cf5108

from molecule-vmware.

sky-joker avatar sky-joker commented on August 16, 2024

Thanks, @antivirtel for reporting the issue.
I tried whether the same error occurs, but the error didn't occur with the following procedure.

$ python3 -m venv venv
$ . venv/bin/activate
(venv)$ pip install --upgrade pip
(venv)$ pip install molecule==3.3.4 molecule-vmware ansible==2.9.22
(venv)$ pip list | grep -e 'Pack' -e '---' -e 'molecule' -e 'ansible'
Package            Version
------------------ ---------
ansible            2.9.22
ansible-lint       5.0.12
molecule           3.3.4
molecule-vmware    0.3.5
(venv)$ mkdir -p roles/sample/tasks
(venv)$ touch roles/sample/tasks/main.yml
(venv)$ cd roles/sample/
(venv)$ molecule init scenario -d vmware
(venv)$ find . -type f
./tasks/main.yml
./molecule/default/molecule.yml
./molecule/default/INSTALL.rst
./molecule/default/converge.yml
./molecule/default/create.yml
./molecule/default/create_linux_instance.yml
./molecule/default/create_windows_instance.yml
./molecule/default/destroy.yml
./molecule/default/verify.yml
./.yamllint
(venv)$ cd ../../
(venv)$ ls
roles  venv
(venv)$ ansible-lint roles

Do you know what I'm doing wrong?

from molecule-vmware.

antivirtel avatar antivirtel commented on August 16, 2024

Do you have register: in ./molecule/default/create_linux_instance.yml?

from molecule-vmware.

sky-joker avatar sky-joker commented on August 16, 2024

Do you have register: in ./molecule/default/create_linux_instance.yml?

Yes.
I'm wondering why the same error didn't occur in my environmentπŸ€”

(venv)$ cat roles/sample/molecule/default/create_linux_instance.yml

create_linux_instance.yml

---
- name: Create keypair
  user:
    name: "{{ lookup('env','USER') }}"
    generate_ssh_key: true
    ssh_key_file: "{{ keypair_path }}"
  register: keypair_result

- name: Create molecule instance(s)
  vmware_guest:
    hostname: "{{ molecule_yml.driver.vcenter_hostname }}"
    username: "{{ molecule_yml.driver.vcenter_username }}"
    password: "{{ molecule_yml.driver.vcenter_password }}"
    validate_certs: "{{ molecule_yml.driver.validate_certs | default(false) }}"
    datacenter: "{{ molecule_yml.driver.datacenter }}"
    cluster: "{{ molecule_yml.driver.cluster | default(omit) }}"
    esxi_hostname: "{{ molecule_yml.driver.esxi_hostname | default(omit) }}"
    folder: "{{ molecule_yml.driver.folder }}"
    name: "{{ item.name }}"
    template: "{{ item.template }}"
    snapshot_src: "{{ item.snapshot_src | default(omit) }}"
    hardware: "{{ item.hardware | default(omit) }}"
    networks: "{{ item.networks }}"
    customization:
      hostname: "{{ item.name }}"
      password: "{{ molecule_yml.driver.vm_password }}"
      dns_servers: "{{ molecule_yml.driver.dns_servers | default(omit) }}"
    wait_for_ip_address: true
    wait_for_customization: true
    state: poweredon
  async: 7200
  poll: 0
  register: async_results
  loop: "{{ molecule_yml.platforms }}"

- name: Check the test instance creation status
  async_status:
    jid: "{{ item.ansible_job_id }}"
  loop: "{{ async_results.results }}"
  register: server
  until: server.finished
  delay: 10
  retries: 300

- name: Check vmware tools status
  vmware_guest_info:
    hostname: "{{ molecule_yml.driver.vcenter_hostname }}"
    username: "{{ molecule_yml.driver.vcenter_username }}"
    password: "{{ molecule_yml.driver.vcenter_password }}"
    validate_certs: "{{ molecule_yml.driver.validate_certs | default(false) }}"
    datacenter: "{{ molecule_yml.driver.datacenter }}"
    folder: "{{ molecule_yml.driver.folder }}"
    name: "{{ item.name }}"
  register: guest_state
  until: "guest_state.instance.guest_tools_status == 'guestToolsRunning'"
  delay: 10
  retries: 300
  loop: "{{ molecule_yml.platforms }}"
  ignore_errors: true

- name: Create ssh directory and public key in guest OS
  vmware_vm_shell:
    hostname: "{{ molecule_yml.driver.vcenter_hostname }}"
    username: "{{ molecule_yml.driver.vcenter_username }}"
    password: "{{ molecule_yml.driver.vcenter_password }}"
    validate_certs: "{{ molecule_yml.driver.validate_certs | default(false) }}"
    datacenter: "{{ molecule_yml.driver.datacenter }}"
    folder: "{{ molecule_yml.driver.folder }}"
    vm_id: "{{ item.name }}"
    vm_username: "{{ molecule_yml.driver.vm_username }}"
    vm_password: "{{ molecule_yml.driver.vm_password }}"
    vm_shell: /bin/bash
    vm_shell_args: "-c 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo {{ keypair_result.ssh_public_key }} > ~/.ssh/authorized_keys'"
    wait_for_process: true
  loop: "{{ molecule_yml.platforms }}"

- name: Populate instance config dict
  set_fact:
    instance_conf_dict: {
      'instance': "{{ instance_info.item.item.name }}",
      'address': "{{ instance_info.instance.ipv4 }}",
      'user': "{{ molecule_yml.driver.vm_username }}",
      'port': 22,
      'identity_file': "{{ keypair_path }}",
      'instance_os_type': "{{ molecule_yml.driver.instance_os_type }}"
    }
  loop: "{{ server.results }}"
  loop_control:
    loop_var: instance_info
  register: instance_config_dict
  when: server is changed

- name: Convert instance config dict to a list.
  set_fact:
    instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
  when: server is changed

- name: Dump instance config
  copy:
    content: "{{ instance_conf | to_json | from_json | to_yaml }}"
    dest: "{{ molecule_instance_config }}"
    mode: 0644
  when: server is changed

from molecule-vmware.

bandit420 avatar bandit420 commented on August 16, 2024

Can confirm same issue.

pip list | grep -e 'Pack' -e '---' -e 'molecule' -e 'ansible'
Package           Version
----------------- ---------
ansible           3.4.0
ansible-base      2.10.10
ansible-lint      5.0.12
molecule          3.3.4
molecule-docker   0.2.4
molecule-goss     1.1
molecule-vmware   0.3.5

As a (ugly) workaround you can ignore paths:

Create .ansible-lint config file and ignore the paths (https://ansible-lint.readthedocs.io/en/latest/configuring.html#configuration-file).

exclude_paths:
- molecule/*/create_linux_instance.yml
- molecule/*/create_windows_instance.yml

At least "molecule lint" is then working for the moment.

from molecule-vmware.

antivirtel avatar antivirtel commented on August 16, 2024

Ansible-lint runs in a Docker container for us, so no venv/pyenv needed there. For the config file .ansible-lint the config exclude_paths: only works without the *, so each role with Vmware testing needs to be listed. So like this:

exclude_paths:
- roles/<rolename1>/molecule
- roles/<rolename2>/molecule

They suggested a fix: ansible/ansible-lint#1622 (comment) - would that be OK?

from molecule-vmware.

sky-joker avatar sky-joker commented on August 16, 2024

@antivirtel

I want to confirm that the error willn't happen by changing the directory structure to fix the issue, but unfortunately, I can't confirm the error in my environment.
I want to make sure that can you check the error not happen in your environment by adopting the suggestion?

from molecule-vmware.

antivirtel avatar antivirtel commented on August 16, 2024
$ pip3 list | grep -e 'Pack' -e '---' -e 'molecule' -e 'ansible'
Package             Version
------------------- ---------
ansible             2.9.22
ansible-lint        5.0.12
molecule            3.3.4
molecule-docker     0.2.4
molecule-vmware     0.3.5

Before:

$ tree roles/<rolename>/molecule/
roles/<rolename>/molecule/
└── default
    β”œβ”€β”€ converge.yml
    β”œβ”€β”€ create_linux_instance.yml
    β”œβ”€β”€ create.yml
    β”œβ”€β”€ destroy.yml
    └── molecule.yml

$ grep create_linux roles/<rolename>/molecule/default/create.yml
    - include_tasks: create_linux_instance.yml

Output before

$ ansible-lint roles
Loading custom .yamllint config file, this extends our internal yamllint config.
WARNING  Listing 4 violation(s) that are fatal
[...3 more...]

syntax-check: 'register' is not a valid attribute for a Play
roles/<rolename>/molecule/default/create_linux_instance.yml:2:3 ERROR! 'register' is not a valid attribute for a Play

The error appears to be in '/home/rbk03/deploy/provisioning/roles/<rolename>/molecule/default/create_linux_instance.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Create keypair
  ^ here

Changing:

$ cd roles/<rolename>/molecule/default/
$ mkdir tasks
$ mv create_* tasks/
$ cd -
$ tree roles/<rolename>/molecule/
roles/<rolename>/molecule/
└── default
    β”œβ”€β”€ converge.yml
    β”œβ”€β”€ create.yml
    β”œβ”€β”€ destroy.yml
    β”œβ”€β”€ molecule.yml
    └── tasks
        └── create_linux_instance.yml

2 directories, 5 files

Tried to modify the path to the task, but doesn't seem to accept it (nor on the original):

$ grep create_linux roles/<rolename>/molecule/default/create.yml
    - include_tasks: ./tasks/create_linux_instance.yml

or these:

$ grep create_linux roles/<rolename>/molecule/default/create.yml
    - include_tasks: tasks/create_linux_instance.yml

$ grep create_linux roles/<rolename>/molecule/default/create.yml
    - include_tasks: ../default/tasks/create_linux_instance.yml

$ grep create_linux roles/<rolename>/molecule/default/create.yml
    - include_tasks: ../<rolename>/molecule/default/tasks/create_linux_instance.yml

$ grep -B1 create_linux roles/<rolename>/molecule/default/create.yml
    - include_tasks:
        file: tasks/create_linux_instance.yml

I always get this error, like the above setting is ignored:

$ ansible-lint roles
Loading custom .yamllint config file, this extends our internal yamllint config.
WARNING  Listing 1 violation(s) that are fatal
internal-error: Unexpected error code 1 from execution of: ansible-playbook --syntax-check --extra-vars {"user_defined_hosts": ["localhost"], "adhoc_ip_address": "127.0.0.1", "inventory_target": "localhost"} roles/<rolename>/molecule/default/create_linux_instance.yml
roles/<rolename>/molecule/default/create_linux_instance.yml:1 ERROR! the playbook: roles/<rolename>/molecule/default/create_linux_instance.yml could not be found


You can skip specific rules or tags by adding them to your configuration file:
# .ansible-lint
warn_list:  # or 'skip_list' to silence them completely
  - internal-error  # Unexpected internal error
Finished with 1 failure(s), 0 warning(s) on 1378 files.

What's the correct line there? I've asked on the other ticket as well: ansible/ansible-lint#1622 (comment)

from molecule-vmware.

sky-joker avatar sky-joker commented on August 16, 2024

@antivirtel

I made a patch(https://github.com/sky-joker/molecule-vmware/pull/21) to fix the issue, so could you please check the error will not happen in your environment?
You can do check with the following procedure.

$ git clone https://github.com/sky-joker/molecule-vmware.git
$ cd molecule-vmware/
$ git checkout -b fix_ansiblelint5_error remotes/origin/fix_ansiblelint5_error
$ pip install .
$ pip install ansible==2.9.22
$ cd ../
$ mkdir -p roles/sample
$ cd roles/sample
$ molecule init scenario -d vmware
$ cd ../../
$ ls
molecule-vmware  roles
$ ansible-lint --exclude molecule-vmware . 

And let me know the result.

from molecule-vmware.

antivirtel avatar antivirtel commented on August 16, 2024

Thank you for the quick fix!

After the patched version:

$ tree molecule/default/
molecule/default/
β”œβ”€β”€ converge.yml
β”œβ”€β”€ create.yml
β”œβ”€β”€ destroy.yml
β”œβ”€β”€ handlers
β”‚Β Β  └── main.yml
β”œβ”€β”€ INSTALL.rst
β”œβ”€β”€ molecule.yml
β”œβ”€β”€ tasks
β”‚Β Β  β”œβ”€β”€ create_linux_instance.yml
β”‚Β Β  └── create_windows_instance.yml
└── verify.yml

2 directories, 9 files

Looks ok now, it revealed our other errors (so gone through this step, issue with Playbooks in Molecule). How can we migrate the current roles (which were already inited)? What exactly do I need to put into the include_tasks: mentioned here?

from molecule-vmware.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.