ansible/molecule

Cannot follow getting started guide 'Creating a new role'

geerlingguy opened this issue · 1 comments

Issue Type

  • Bug report

Molecule and Ansible details

$ ansible --version && molecule --version
ansible [core 2.15.0]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/Users/jgeerling/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/jgeerling/Library/Python/3.9/lib/python/site-packages/ansible
  ansible collection location = /Users/jgeerling/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/jgeerling/Library/Python/3.9/bin/ansible
  python version = 3.9.6 (default, Mar 10 2023, 20:16:38) [Clang 14.0.3 (clang-1403.0.22.14.1)] (/Library/Developer/CommandLineTools/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
molecule 5.0.1 using python 3.9 
    ansible:2.15.0
    azure:23.4.1 from molecule_plugins
    containers:23.4.1 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
    delegated:5.0.1 from molecule
    docker:23.4.1 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
    ec2:23.4.1 from molecule_plugins
    gce:23.4.1 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
    podman:23.4.1 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
    vagrant:23.4.1 from molecule_plugins

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Detail any linters or test runners used: N/A

Desired Behavior

If I run molecule init role acme.my_new_role --driver-name docker (as specified in the getting started guide), I should have a new role named my_new_role in the current directory, and no errors should display in the command output.

Actual Behaviour

After installing a fresh instance of Ansible + Molecule, and running the above command, I get:

$ molecule init role acme.my_new_role --driver-name docker  
INFO     Initializing new role my_new_role...
Using /etc/ansible/ansible.cfg as config file
- Role my_new_role was created successfully
127.0.0.1 | UNREACHABLE!: Data could not be sent to remote host "127.0.0.1". Make sure this host can be reached over ssh: ssh: connect to host 127.0.0.1 port 22: Connection refused
WARNING  Retrying execution failure 4 of: ansible localhost -o -m lineinfile -a path=my_new_role/meta/main.yml line="  namespace: acme" insertafter="  author: your name"
Traceback (most recent call last):
  File "/Users/jgeerling/Library/Python/3.9/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/molecule/command/init/role.py", line 174, in role
    r.execute()
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/molecule/command/init/role.py", line 102, in execute
    util.run_command(cmd, check=True)
  File "/Users/jgeerling/Library/Python/3.9/lib/python/site-packages/molecule/util.py", line 156, in run_command
    raise CalledProcessError(
subprocess.CalledProcessError: Command '['ansible', 'localhost', '-o', '-m', 'lineinfile', '-a', 'path=my_new_role/meta/main.yml line="  namespace: acme" insertafter="  author: your name"']' returned non-zero exit status 4.

I'm on a Mac running macOS Ventura 13.4 with Docker Desktop 4.17.0.

Possibly related: #3678

@geerlingguy

I cannot reproduce the issue on my MacOS.

I guess it may be because of Using /etc/ansible/ansible.cfg as config file.
Can you try to temporarily rename/remove the /etc/ansible/ansible.cfg and try again?

BTW, could you please show me the content of this file?