Questions tagged [ansible-api]

Use this tag for questions regarding Ansible Python API.

Ansible Python API is a Python interface to Ansible allowing the control nodes, extending Ansible to respond to various python events, writing plugins, and connecting to external data sources.

26 questions
4
votes
1 answer

How to run playbook api in Ansible v2

I want to run ansible playbook via Ansible V2 python api. Here is my way: from ansible.parsing.dataloader import DataLoader from ansible.vars import VariableManager from ansible.inventory import Inventory from ansible.executor.playbook_executor…
Binary
  • 81
  • 8
3
votes
1 answer

How to call ansible playbooks using python API

I need a help with Ansible to run programatically. I using ansible 2.7 and trying to use Python API for calling the ansible plabooks programatically But the API from https://docs.ansible.com/ansible/latest/dev_guide/developing_api.html does not have…
Vijay
  • 5,331
  • 10
  • 54
  • 88
3
votes
1 answer

How to run playbook api in Ansible v2 with vault

Here is what I have, I know this works without encryption and I can run ansible-vault edit common.yml with ANSIBLE_VAULT_PASSWORD_FILE=~/.vault_pass.txt set in the env. from collections import namedtuple from ansible.parsing.dataloader import…
user2363318
  • 1,039
  • 1
  • 12
  • 31
2
votes
1 answer

Getting Ansible Tower API authentication token from C#

I tried using this C# code below, but getting status code 401 (reason:unautherized): var baseUri = "https://ansibletower1.test1.com"; var data = @"{'username':'test123', 'password':'a1b2c3Z0!-99', 'description':'Ansible Api token',…
Mahesh
  • 309
  • 4
  • 8
2
votes
0 answers

Ansible get return value from tasks execution with Python Api

Is there a way to get the return values from the execution of a module? For example https://docs.ansible.com/ansible/latest/modules/ec2_vpc_subnet_module.html To get for example the vpc_id. I am using the PlaybookExecutor but it only returns the…
Radaeld
  • 175
  • 1
  • 2
  • 9
2
votes
0 answers

Append role to a playbook in Ansible 2.0 Python API

Building on this question How to use Ansible 2.0 Python API to run a Playbook? How can I create an instance of PlaybookExecutor class and append an Ansible role that will be executed when pbex.run() is called? This is an example Playbook ls.yml -…
user3138929
  • 369
  • 5
  • 18
2
votes
0 answers

How do you extract registered variables returned from an ansible playbook?

I have a playbook task like this: tasks: - shell: /usr/bin/foo register: foo_result I'm running this playbook using the python API, and I would like to do some post processing on the foo_result variable. How do I access foo_result using the…
pixelrebel
  • 61
  • 4
1
vote
0 answers

How to use Ansible Python API to run ansible task

I would like to use Ansible 2.9.9 Python API to get config file and parse it to json format from servers in hosts file. I don't know how to call an existing ansible task using Python API. Through the Ansible API document, how to integrate ansible…
kanpai
  • 25
  • 3
1
vote
1 answer

Ansible include_tasks giving syntax error

Ansible version: 2.9 Play book --- - { include_tasks: test.yml } Error The error appears to have been in '/path/to/main.yml': line 34, column 3, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to…
Shahid Karimi
  • 4,096
  • 17
  • 62
  • 104
1
vote
0 answers

Null values passed to cloudformation module - ansible

Ansible cloudformation module uses these environment variables of shell: $ export AWS_PROFILE=djangoapp $ export AWS_DEFAULT_REGION=ca-central-1 $ aws configure list Name Value Type Location ---- …
overexchange
  • 15,768
  • 30
  • 152
  • 347
1
vote
1 answer

Ansible : error in calling the groups through restapi

I am trying fetch to distinct groups in the inventory through a variable.this is the command am trying to run in the playbook to add hosts to the Nagios XI. Am trying to do this using Rest API through CURL command. Am getting error as Incorrect…
user9698169
1
vote
1 answer

Calling a filter plugin from an action plugin

I am developing a custom Ansible action plugin. From in there I would like to calculate the gateway and subnet mask from an CIDR. This is already possible with the ipaddr filter. Instead of replicating the code, is there a way to call the ipaddr…
udondan
  • 57,263
  • 20
  • 190
  • 175
1
vote
1 answer

ansible runner runs to long

When I use ansible's python API to run a script on remote machines(thousands), the code is: runner = ansible.runner.Runner( module_name='script', module_args='/tmp/get_config.py', pattern='*', forks=30 ) then, I use datastructure =…
page
  • 52
  • 6
1
vote
2 answers

Ansible API : Custom Module

I would like to use a custom module for which I require "hostname" so that I can initiate SSH connection from the custom module and run commands. So I pass transport = "local" to the Runner object. However, I find no way to obtain "hostname"…
user3267989
  • 299
  • 3
  • 18
1
vote
0 answers

****ansible.errors.AnsibleError: Unable to find an inventory file, specify one with -i ?****

****ansible.errors.AnsibleError: Unable to find an inventory file, specify one with -i ?**** My script : #!/usr/bin/python import ansible.playbook from ansible import callbacks from ansible import utils ANSIBLE_HOSTS = 'hosts' PLAYBOOK =…
1
2