Molecule: Place to setup ansible_python_interpreter

Created on 1 Jul 2016  路  10Comments  路  Source: ansible-community/molecule

I don't understand where i should put ansible_python_interpreter.
because FreeBSD use alternate path.

Most helpful comment

Library Versions

  • Molecule: 2.17.0
  • Ansible: 2.6.3

It took me a while to figure out how to make this work properly so I thought I would post my solution for others to see. If you want to set the ansible_python_interpreter for a host, then you need to define a key under host_vars that matches the name of your platform.; see below.

# molecule.yml
platforms:
  - name: my_instance
    box: my_box
provisioner:
  name: ansible
  lint:
    name: ansible-lint
  inventory:
    host_vars:
      my_instance:
        ansible_python_interpreter: "/home/core/bin/python"

All 10 comments

I don't believe you need to. You could simply setup a virtualenv on the box running molecule.

virtualenv --no-setuptools venv
source venv/bin/activate
pip install molecule

that is my setup

ansible:
  raw_env_vars:
    http_proxy: "http://192.168.1.43:3128"
    https_proxy: "http://192.168.1.43:3128"
vagrant:
  platforms:
    - name: freebsd
      box: freebsd/FreeBSD-11.0-ALPHA5
  providers:
    - name: virtualbox
      type: virtualbox
      options:
        memory: 2048
        cpus: 2
  instances:
    - name: tower-01
      ansible_groups:
        - group_1
      interfaces:
        - network_name: private_network
          type: dhcp
          auto_config: true
      options:
        append_platform_to_hostname: no

so i am using freebsd
and i got this

% molecule converge

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
fatal: [tower-01]: FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "/bin/sh: /usr/bin/python: not found\r\n", "msg": "MODULE FAILURE", "parsed": false}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @playbook.retry

PLAY RECAP *********************************************************************
tower-01                   : ok=0    changed=0    unreachable=0    failed=1

so in the vm

root@:/home/vagrant # which python
python: Command not found.
root@:/home/vagrant # which python2.7
/usr/local/bin/python2.7

also
http://docs.ansible.com/ansible/intro_bsd.html

currently i fix it like this.

% cat .molecule/ansible_inventory
tower-01 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=/home/shirokih/.vagrant.d/insecure_private_key ansible_ssh_user=vagrant ansible_python_interpreter=/usr/local/bin/python2.7


[group_1]
tower-01

than i add chattr +i .molecule/ansible_inventory
and it works..
but freebsd it the only one of supported environments. i have to test on 5.

  • debian
  • ubuntu
  • freebsd
  • centos
  • rhel

my playbook support it, and currently i am looking for a way to test it. molecule looks right tool for it. especially with last feature for testinfra test parametrization.

Does something like this work?

ansible:
  extra_vars: ansible_python_interpreter=/usr/local/bin/python2.7
  raw_env_vars:
    http_proxy: "http://192.168.1.43:3128"
    https_proxy: "http://192.168.1.43:3128"
...

It looks like #202 is probably what you're after so you can set vars by group or host rather than the hack I mentioned above.

looks no. because ansible config applied for every host. but i need to define in only for frebsd instance

So, while we wait for #202 to land, you can probably do something like the following:

molecule.yml:

...
  instances:
    - name: tower-01
      ansible_groups:
        - group_1
        - bsd
      interfaces:
        - network_name: private_network
          type: dhcp
          auto_config: true

playbook.yml

- hosts: bsd
  vars:
    ansible_python_interpreter: /usr/local/bin/python2.7

- hosts: all
  roles:
    - role: ...

@freeseacher was your question answered?

Closing. Please re-open if you still have issues.

so. can you please add some example with two boxes.

  • debian/jessie64
  • freebsd/FreeBSD-11.0-BETA2
    that will work without changing molecule.yml for every test
    my current file is
molecule:
  test:
    # sequence of commands to run when performing `molecule test`
    sequence:
      - destroy
      - create
      - converge
      - verify
vagrant:
  raw_config_args:
    - "ssh.insert_key = false"
  platforms:
    - name: freebsd
      box: freebsd/FreeBSD-11.0-BETA2
    - name: ubuntu
      box: ubuntu/xenial64
    - name: centos
      box: centos/7
    - name: debian
      box: debian/jessie64
  providers:
    - name: virtualbox
      type: virtualbox
      options:
        memory: 2048
        cpus: 2
  instances:
    - name: tower-01
      ansible_groups:
        - group_1
      interfaces:
        - network_name: private_network
          type: dhcp
          auto_config: true
      options:
        append_platform_to_hostname: no

ansible:
  raw_env_vars:
    http_proxy: "http://192.168.1.43:3128"
    https_proxy: "http://192.168.1.43:3128"

what files i should change for it ?

Library Versions

  • Molecule: 2.17.0
  • Ansible: 2.6.3

It took me a while to figure out how to make this work properly so I thought I would post my solution for others to see. If you want to set the ansible_python_interpreter for a host, then you need to define a key under host_vars that matches the name of your platform.; see below.

# molecule.yml
platforms:
  - name: my_instance
    box: my_box
provisioner:
  name: ansible
  lint:
    name: ansible-lint
  inventory:
    host_vars:
      my_instance:
        ansible_python_interpreter: "/home/core/bin/python"
Was this page helpful?
0 / 5 - 0 ratings