Code Monkey home page Code Monkey logo

ansible-run_playbook's Introduction

Ansible - Run Playbook

This is an example of how to run Ansible v2 Playbook programatically.

Usage

$ cd env
$ ../run.py

PLAY [Test play] ***************************************************************

TASK [Debug task] **************************************************************
ok: [localhost] => {
    "msg": "Hello world!"
}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0

Resources

Author

Jiri Tyr

License

MIT

ansible-run_playbook's People

Contributors

jtyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansible-run_playbook's Issues

TypeError: 'NoneType' object is not iterable

@jtyr I have downloaded your repo and run it with any change for testing and getting this error, can you please tell me how I can resolve it as I don't have much idea to run the ansible inside python. Thanks

vagrant@tendo:/vagrant-nfs/project/env$ ../run.py
Traceback (most recent call last):
  File "../run.py", line 140, in <module>
    main()
  File "../run.py", line 134, in main
    stats = runner.run()
  File "../run.py", line 106, in run
    self.pbex.run()
  File "/usr/local/lib/python2.7/dist-packages/ansible/executor/playbook_executor.py", line 153, in run
    result = self._tqm.run(play=play)
  File "/usr/local/lib/python2.7/dist-packages/ansible/executor/task_queue_manager.py", line 242, in run
    play_context = PlayContext(new_play, self._options, self.passwords, self._connection_lockfile.fileno())
  File "/usr/local/lib/python2.7/dist-packages/ansible/playbook/play_context.py", line 237, in __init__
    self.set_options(options)
  File "/usr/local/lib/python2.7/dist-packages/ansible/playbook/play_context.py", line 303, in set_options
    self.only_tags.update(options.tags)
TypeError: 'NoneType' object is not iterable
vagrant@tendo:/vagrant-nfs/project/env$

Ansible version

vagrant@tendo:/vagrant-nfs/project/env$ ansible --version
ansible 2.3.0.0
  config file = /vagrant-nfs/project/env/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
vagrant@tendo:/vagrant-nfs/project/env$

Failed to get plugins

Hello,

When I try your script I get:

Loaded callback default of type stdout, v2.0

PLAYBOOK: play.yml *************************************************************
1 plays in /tmp/test/play.yml

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

TASK [setup] *******************************************************************
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/home/b02472/.virtualenvs/csa_yaml/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 124, in run
    res = self._execute()
  File "/home/b02472/.virtualenvs/csa_yaml/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 411, in _execute
    self._connection = self._get_connection(variables=variables, templar=templar)
  File "/home/b02472/.virtualenvs/csa_yaml/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 636, in _get_connection
    connection = self._shared_loader_obj.connection_loader.get(conn_type, self._play_context, self._new_stdin)
  File "/home/b02472/.virtualenvs/csa_yaml/lib/python2.7/site-packages/ansible/plugins/__init__.py", line 328, in get
    path = self.find_plugin(name)
  File "/home/b02472/.virtualenvs/csa_yaml/lib/python2.7/site-packages/ansible/plugins/__init__.py", line 291, in find_plugin
    if not name.startswith('_'):
AttributeError: 'NoneType' object has no attribute 'startswith'

fatal: [XXX.intra]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @/tmp/test/play.retry

PLAY RECAP *********************************************************************
XXX.intra : ok=0    changed=0    unreachable=0    failed=1

if I modify "ansible/plugins/init.py +291" to check for the name variable nullity before checking if its start with an uderscore i get:

Loaded callback default of type stdout, v2.0

PLAYBOOK: play.yml *************************************************************
1 plays in /tmp/test/play.yml

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

TASK [setup] *******************************************************************
fatal: [XXX.intra]: FAILED! => {"failed": true, "msg": "the connection plugin 'None' was not found"}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @/tmp/test/play.retry

PLAY RECAP *********************************************************************
XXX.intra : ok=0    changed=0    unreachable=0    failed=1

There is definitely something going wrong about plugin/module import that I can't manage to figure out. If you have any clue ?

Ansible version 2.1 installed via pip or ansible 2.0

Regards

Seeing "Specified limit does not match any hosts." on passing hosts file

Hi, on passing a host file when creating the runner object I see "Specified limit does not match any hosts." Any clue what I'm missing?
The host file looks as follows:
[undercloud]
undercloud
[controller]
overcloud-controller-0
[compute]
overcloud-compute-0
overcloud-compute-1
Help is greatly appreciated. Thanks!

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.