Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29259

How to fix template error while templating string: no filter named 'molecule_from_yaml' with molecule ec2 driver

$
0
0

I am running a Molecule v2.22 and I am want to spin up an ec2 instance using molecule, to test my ansible playbooks.
But I am hitting an error when molecule gets to the Detroy and create stage of the instance.

I also don't understand why molecule is skipping the /usr/lib/python2.7/site-packages/molecule/provisioner/ansible/plugins/filters/molecule_core.py plugin, which I believe could be responsible for the filter named molecule_from_yaml

See below errors:

 [WARNING]: Skipping plugin (/usr/lib/python2.7/site-packages/molecule/provisioner/ansible/plugins/filters/molecule_core.py) as itseems to be invalid: cannot import name py31compat    PLAY [Destroy] *****************************************************************    TASK [Populate instance config] ************************************************    fatal: [localhost]: FAILED! => {"msg": "template error while templating string: no filter named 'molecule_from_yaml'. String: {{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"}--> Action: 'create' [WARNING]: Skipping plugin (/usr/lib/python2.7/site-packages/molecule/provisioner/ansible/plugins/filters/molecule_core.py) as itseems to be invalid: cannot import name py31compat    PLAY [Create] ******************************************************************    TASK [Get the ec2 ami(s) by owner and name, if image not set] ******************    fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while templating '{{ lookup('file', molecule_file) | molecule_from_yaml }}'. Error was a <class 'ansible.errors.AnsibleError'>, original       message: template error while templating string: no filter named 'molecule_from_yaml'. String: {{ lookup('file', molecule_file) | molecule_from_yaml }}"}

Below is the destroy.yml file that destroys the previously created instances if there is one.

- name: Destroy  hosts: localhost  connection: local  gather_facts: false  tasks:    - block:        - name: Populate instance config          set_fact:            instance_conf: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"            skip_instances: false      rescue:        - name: Populate instance config when file missing          set_fact:            instance_conf: {}            skip_instances: true    - name: Destroy molecule instance(s)      ec2:        state: absent        instance_ids: "{{ item.instance_ids }}"      register: server      with_items: "{{ instance_conf }}"      when: not skip_instances      async: 7200      poll: 0    - name: Wait for instance(s) deletion to complete      async_status:        jid: "{{ item.ansible_job_id }}"      register: ec2_jobs      until: ec2_jobs.finished      retries: 300      with_items: "{{ server.results }}"    # Mandatory configuration for Molecule to function.    - name: Populate instance config      set_fact:        instance_conf: {}    - name: Dump instance config      copy:        content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"        dest: "{{ molecule_instance_config }}"      when: server.changed | bool

Below is the create.yml

---- name: Create  hosts: localhost  connection: local  gather_facts: false  no_log: "{{ molecule_no_log }}"  vars:    ssh_user: ubuntu    ssh_port: 22    keypair_name: mpho_csosecuritydev.pem    keypair_path: /home/ec2-user/mpho_csosecuritydev.pem    security_group_name: euw1-cso_securitydev_run_ansible-sg  tasks:    - name: Get the ec2 ami(s) by owner and name, if image not set      ec2_ami_facts:        owners:        filters:          name: "{{ item.image_name }}"      loop: "{{ molecule_yml.platforms }}"      when: item.image is not defined      register: ami_facts    - name: Create molecule instance(s)      ec2:        key_name: "{{ keypair_name }}"        image: ami-08cb423ed619f        instance_type: t2.micro        vpc_subnet_id: subnet-07b35        group: "{{ security_group_name }}"        instance_tags:          Name: seceng-molecule-test-amz2        wait: true        assign_public_ip: false        instance_profile_name: euw1-ansible_run-instance_profile        exact_count: 1        count_tag:          instance: seceng-molecule-test-amz2      register: server      #      loop: '{{ lookup("file", molecule.yml) | molecule_from_yaml }}'      loop_control:        index_var: index      async: 7200      poll: 0    - name: Wait for instance(s) creation to complete      async_status:        jid: "{{ item.ansible_job_id }}"      register: ec2_jobs      until: ec2_jobs.finished      retries: 300      with_items: "{{ server.results }}"    # Mandatory configuration for Molecule to function.    - name: Populate instance config dict      set_fact:        instance_conf_dict: {'instance': "{{ item.instances[0].tags.instance }}",'address': "{{ item.instances[0].public_ip }}",'user': "{{ ssh_user }}",'port': "{{ ssh_port }}",'identity_file': "{{ keypair_path }}",'instance_ids': "{{ item.instance_ids }}", }      with_items: "{{ ec2_jobs.results }}"      register: instance_config_dict      when: server.changed | bool    - 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.changed | bool    - name: Dump instance config      copy:        content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"        dest: "{{ molecule_instance_config }}"      when: server.changed | bool    - name: Wait for SSH      wait_for:        port: "{{ ssh_port }}"        host: "{{ item.address }}"        search_regex: SSH        delay: 10        timeout: 320      with_items: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"    - name: Wait for boot process to finish      pause:        minutes: 2

I hope I have provided adequate information for this issue


Viewing all articles
Browse latest Browse all 29259

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>