cloud,state,conditional-statements,ansible,openstack , How to conditionally check the state of an openstack instance

How to conditionally check the state of an openstack instance


Tag: cloud,state,conditional-statements,ansible,openstack

I am trying to conditionally check the state of an openstack cloud instance in my playbook.

The playbook itself takes the name of a cloud instance as a parameter and then deletes it by setting the state to absent using nova compute. What I want to do is check if the state is already absent (say the name of a non-existent instance has been entered) to skip the statement. How would I write that?

- nova_compute
     name: "{{item}}"
     state: absent
  with_items: "{{instance_name}}"
  when: ???


I'm not familiar with the openstack tasks, but it looks like this shouldn't be terribly difficult to do. First off, if all you want to do is terminate all your instances and you're getting an error because some already don't exist then simply ignoring errors might suffice:

- nova_compute
     name: "{{item}}"
     state: absent
  with_items: "{{instance_name}}"
  ignore_errors: yes

If you don't want to do that then you'd need to split this out into multiple tasks, one to check the state of the instance(s) and another one to terminate them.

The Ansible documentation looks like it's recently been updated for Ansible 2.0, so I'm not sure if the module names have changed sufficiently or not, but given what's currently documented I'd suggest using a task to gather facts for the instance in question. If the task returns an error then the instance doesn't exist, which is what you're really after, so something like this should work:

- os_server_facts
      name: "{{instance_name}}"
      register: instance_state
      ignore_errors: yes

And then you can do something like this:

- nova_compute
      name: "{{instance_name}}"
      state: absent
      when: instance_state is not defined 

Depending on what the first task returns for instance_state you might want the when clause to be a bit more structured. I'd suggest running a few tests and outputting instance_state via the debug module to see if you need to do anything beyond what I provided here.

If you need to do this with a list of instances you should be able to expand the tasks a bit to do that as well. Something along these lines (obviously I haven't actually tested these so they may not be 100% correct):

- os_server_facts
      name: "{{item}}"
      register: instance_state
      ignore_errors: yes
      with_items: "{{instance_list}}"

- nova_compute
      name: "{{item}}"
      state: absent
      when: instance_state[item] is not defined 
      with_items: "{{instance_list}}"


Did google change/update related to vm ssl connections to Cloud SQL?

Google Cloud SQL down? At 1am ET my VM connection to Cloud SQL over SSL decided to stop connecting and will not allow a connection. Did google make changes/updates? Has been working fine for months, no changes, then all of a sudden this morning at 1am ET BAM! Won't connect...

What does (extra requests) mean in services?,notifications,push-notification,cloud,push
In Parse's pricing FAQ it is mentioned that "If your app hits its request limit, your extra requests will begin to fail with error code 155 (RequestLimitExceeded)". What does (extra requests) mean? Are they the requests made within the same minute? day? month? or all other requests made until the...

Parse cloud code check for key duplication,cloud
I developed an iOS app using Parse. When user sign up, I want to check if his phone number exist. So I write the following Parse Cloud Code: Parse.Cloud.beforeSave(Parse.User, function(request, response) { var toSaveObjectId = request.object.get("objectId"); console.log("UserName: "); console.log(request.object.get('username')); //if (typeof != 'undefined') if (typeof toSaveObjectId != 'undefined') {...

AngularJS $location.path looping back to root

I've looked everywhere, but none of the potential solutions have worked. The sign-in page is supposed to route to the tabs page upon a successful login or registration. For some reason it is directing back to the root, or otherwise state every time. Does anyone have any suggestions? Thanks! States:...

UI-Router : Prevent access to parent state

I am moving to UI-Router as my App router. I want to have nested state as below: $stateProvider .state('app', { url: '/app', template: ' <div ui-view></div>', authenticate: true }) .state('app.state1', { url: '/state1', templateUrl: 'app/state1.html', controller: 'State1Ctrl', controllerAs: 'state1', authenticate: true }) .state('app.state2', { url: '/state2', templateUrl: 'app/state2.html', controller: 'State2Ctrl',...

Running cloudfoundry sample app on local sandbox

This question may seem pretty naive but I've just started using cloud foundry. I installed the eclipse plugin & deployed a sample app. But everytime, while running the app in local or starting the server it is being pushed to the remote cloud server & running on a unique domain...

Are private clouds scalable during demand variations?

Whenever someone talks about advantages of cloud computing they say flexibility and scalability. When using a public cloud, when I'm not using the power, someone else is, but what about a private cloud? Lets say a company uses a private cloud. If the company is growing, adding more hypervisors or...

Spark - How to count number of records by key

This is probably an easy problem but basically I have a dataset where I am to count the number of females for each country. Ultimately I want to group each count by the country but I am unsure of what to use for the value since there is not a...

Reduce Storage, By Juggling Packets in Network?

I want to preface this by saying, I have a feeling that this idea will not work the way I'm imagining, but I'm sure why. Its likely I'm making some sort of false assumption about the way the internet works. Lets say server A has a file of size 1024...

Capture UI router's state change when there is no change

I would like to use UI router's $stateChangeStart to capture state change when transiting from '/foo/bar' to '/foo/bar': $rootScope.$on('$stateChangeStart', function() { // ... });' Essentially, I would like to capture when the link for the current state was clicked so I can force reload.... To Do web app deployment issue

Apologies for basic question. I am very new in web development . I have download javascript web To Do App from . Now I want to deploy with So that I can browse this app using But when try to deploy using "parse deploy" command getting...

UI-Router $stateParams With Master Detail Pattern

I need a Master Detais pattern for my web site. In index lots of thumbnails and every thumbnail link to their detailed page. I make a progress but does not get to work. Its load thumbnails on index oage but when I click to thumbnails its load blank page. Index:...

Authenticate Google Account with php

Is there a possibility to log in on to Google Accountt with php? Until 26th of May I was using to verify account. Now this method is disabled. What Im trying to do is to connect Google Printer Cloud to print orders in resaturant. Client makes order on website...

Digi Device API reading Datastream / DIO / AD

I have XBee Gateway ZB, Wifi and I'm experimenting with the Digi Device API. I already tried the Heroku App and it works really good. So I wanted to access online the Datastream. Using Google Spreadsheet or something like this. So reading the documentation from digi. I could acces...

Installing CouchDB on IaaS?

After many many google searches I am still unclear on how to install a CouchDB instance on an Infrastructure as a Service cloud service. I have looked into DBaaS options such as Cloudant, but for initial testing I would like to host the database on an IaaS. Specifically, I am...

Telescope back button state

Checking Telescope, and it looks pretty great, but... Is the back button broken when using search? After entering a search term, if you click on a thread and then hit the browser's back button, Telescope displays the correct search url, but there are no search results. This makes using search...

Angular ui.router. Deep nested routes

Here is an example to check When we navigate to 'page2' route there is a 'hey, I'm a subroute' note. But once we navigate anywhere else that note will disappear forever. The goal is to make some nested states to be shown right away (as a default ones). I...

React Native Change State With Unexpected Logging

For context, I am working on this React Native Tutorial The way this logs confuses me. The following is the console output when I changed an empty input field by typing "a" then "b". Here's my SearchPage class. Why does console.log('searchString = ' + this.state.searchString); show the previous value for...

GoogleCloudMessaging - InstanceID.getInstance(), registering from client

I'm pretty new to programming in Java and generally programming. Right now I decided to make my own app that is supposed to utilize Google Cloud Messaging. And somehow I succeeded but then I realized I used method String regid = gcm.register(PROJECT_NUMBER); that is deprecated and I should now use...

Adding a second Heroku app to my local repo, I'm denied access to my apps

I originally had a setup like: git remote -v origin [email protected]: (fetch) origin [email protected]: (push) stage [email protected]: (fetch) stage [email protected]: (push) where I could push and pull from stage without an issue and run commands like heroku run console --app stage however, I added a production app locally leaving me...

Running python script on Microsoft Azure

I'll have a linux machine with a virtual machine installed for Microsoft azure soon. I need to run some data mining/graph analysis algorithms on the azure because I work with big data. I don't want to use azure machine learning stuff. just want to run my own python code. What...

Call State Always : “ERROR_USER_UNAVAILABLE” Linphone manager Android

I want to make application that can call with using Linphone library, but why when I want to call a number (this number can be called using usual phone apps), it always state : "ERROR_USER_UNAVAILABLE" private void call(String ticket_id) { updateState("CALLING"); Log.d(TAG_CALL, "try to call"); LinphoneManager.getInstance().newOutgoingCall(msisdn, ticket_id); callingAttemptHandler.postDelayed(callingAttempt, 1000 *...

C# and Oracle, login Form: Operation is not valid due to the current state of the object

private void bLogIn(object sender, EventArgs e) { string logging = "select * from CLIENT where LOGIN='" + this.t_Login.Text + "' and PASSWORD='" + this.t_Password.Text + "' ;"; OracleConnection conn = new OracleConnection("Data Source=XXX/orcl;User Id=XXX;Password=XXX;"); OracleCommand cmd = new OracleCommand(); cmd.CommandText = logging; cmd.Connection = conn; try { conn.Open(); }...

How to preserve loaded javascript content in a WebView when loading a new page?

In a WebView I can load javascript code by running view.stringByEvaluatingJavaScriptFromString or loading the code directly in the JS context you can retrieve via view.mainFrame.javaScriptContext. However, when I navigate to a new URL (be it in the WebView.mainFrame or in Javascript, e.g. by setting window.location) all my javascript code is...

How to get Office 365 service location via API

I am trying to find the region of an Office 365 service. Microsoft's Office 365 documentation states that the data storage regions are disclosed to the customer. Is it possible to find a service's region via an API request? I've been looking through documentation on the Service Communications API, the...

Relation replacement in Parse Cloud

In a Parse Cloud function I need to replace the value of a relation. How do I do that? Here is my code: Parse.Cloud.define (“myCloudFunction”, function(request, response) { // Code to get myObject ……. // ……… // Now I have myObject in the hand. myObject.relation("author").add(NewAuthor); }); If I keep this...

viewing google app engine Python logging messages in CodeEnvy

I'm trying to move my GAE development to the cloud. So far Codeenvy has the richest toolset however I'm struggling with one small issue. when I use the python logging library I don't know where to view these messages! def post(self): self.response.write('Processing form data...') feedback = self.request.get('content') I assumed...

Creating a scalable database for android app | cloud hosted

I am working to launch an app which in future will store huge number of users and there profile information. But I Wanted to start small to pre-test my app idea , so what will be the options for hosting database which are cost effective initially and scalable in future...

State Machine in Python: Run Code in Transition or State?

I am rather new to the python language, please bear with me on this one. I want to run two state machines in two separate threads, communicating to each other via a queue. I used the transitions package to create the state machine. My understanding is that all actions/code that...

How scale up/out mechanism works in OpenStack and Cloudfoundry integration?

I just started investigating OpenStack & Cloudfoundry recently, and I just wonder how scale up/out mechanism works in OpenStack & Cloudfoundry integration. As far as I understand, if we need to scale-up a web app, Cloudfoundry will try to create a new container to run new web app. If it...

How to create a secure git repository in the cloud?

I would like to create a git repository and keep a backup copy of it in the cloud. Creating a remote repository would be a simple solution, but the code would be open to anyone with access to the cloud machine, thus compromised. Currently I manage this git repository in...

Grunt, cloud deployment and compiled files

I've recently started exploring grunt and I've done so by trying out the seed. It uses a gruntfile to copy static assets, css, javascript to a destination folder with this code: dist_js: { files: [{ src: ['<%= app_files.js %>', '<%= vendor_files.js %>'], dest: '<%= dist_dir %>/public', cwd: '.', expand:...

Reading part of a file in S3 using Boto

I am trying to read 700MB file stored in S3. How ever I only require bytes from locations 73 to 1024. I tried to find a usable solution but failed to. Would be a great help if someone could help me out....

Alternate to run window service in Azure cloud

We currently have a window service which send some notification emails to users after doing some processing on database(SQL database). Runs once in day. We want to move this on azure cloud. One alternate is to put it on Azure VM as is. but I am finding some other best...

How to conditionally check the state of an openstack instance

I am trying to conditionally check the state of an openstack cloud instance in my playbook. The playbook itself takes the name of a cloud instance as a parameter and then deletes it by setting the state to absent using nova compute. What I want to do is check if...

Identifying duplicate requests fired from back end

I am facing a use case where I need to track down duplicate requests, which are fired through REST API calls from back end. Each request writes into the database, and hence the duplicate requests need not be processed again. The duplicate requests may come in different threads under the...

spring cloud config client not loading configuration from config server

I am following this link: I tested this again and again and not seeing Spring cloud client is loading configuration from cloud server, please help to see where is the error: POM: <dependencies> <dependency> <groupId></groupId> <artifactId>spring-cloud-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId>...

How to delete functions of previous instances of controller?

I have a simple angularjs controller referenced as someCtrl and it contains the following code: function testing() { console.log("Hello there."); } $document.on('click', function(e) { testing(); }); this.getView = function(value) { return viewService.getView(value); }; this.setView = function(value) { viewService.setView (value); }; this.destroy = function() { $state.reload('default_state'); }; When click event happens,...

Writing an IAM policy and CORS configuration for Amazon S3

I am very new to all this but have been able to get an avatar/image uploader to work in my Rails application. A user can upload a new avatar to my S3 bucket and the avatar shows within the web application. To this end, I've had to grant "AmazonS3FullAccess" policy...

LinkedIn Rest API, State token doesn't match

I am referring this to authorize, authenticate and login to LinkedIn account using Rest API, but now i am facing problem, the WebView where i am displaying the LinkedIn Rest API call url view, is returning blank with message as "State token doesn't match" It was working fine earlier, but...

State pattern: Identify state class type from string

Background I have a command that uses the state pattern. When the command state changes I am notified in the UI that for example class stageOneState is now the active state. Is it bad practice to check the state class type using a string as an identifier? Is this undoing...

Detecting multiple key presses in C# and XNA 4.0

I want to detect if a specific set of keyboard keys are being held down at once in C# and XNA 4.0. I'm doing so with the following code: KeyboardState keyState = Keyboard.GetState(); if(keyState.IsKeyDown(Keys.S) && keyState.IsKeyDown(Keys.K) && keyState.IsKeyDown(Keys.I)) { //Do something } This code detects if the user is pressing...

Inject a template in parent's view with ui-router

I have an abstract state declared as $stateProvider.state('myapp', { abstract: true, templateUrl : 'index.html' }); And all the <ui-view> in the 'index.html' template will be populated by the children states: $stateProvider.state('myapp.home', { url : "/", views : { "main" : { controller : 'HomeCtrl', templateUrl : 'includes/home.html' } } });...

ssl error record too long using UI CloudStack

I have just finished automatic installation of CloudStack. Now I want to connect to the user interface with Firefox on a remote host. So I enter and I get the error ssl_error_rx_record_too_long How can I solve this? I can only use cli to interact with the CloudStack Server....

how to run a static site on bitnami and AWS?

I am quite a noob when it comes to cloud based apps, this is a completely new context for me. I currently got the github education pack, part of it was an account on bitnami. I was wondering if it's possible to host a static html site on bitnami, I...

When upload Bitmap stream to Azure storage, it store zero/empty image,azure,cloud
I am using below code to upload a MemoryStream from a bitmap image to my Microsoft azure storage account: MemoryStream memoryStream = new MemoryStream(); img.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); blob.Properties.ContentType = model.File.ContentType; blob.UploadFromStream(memoryStream); What happen by use above code is it uploads an empty image to Azure storage :( !(I found the name...

How to save my data in a cloud?

I don't know if this is possible, but I would like to save some data of my website, like images and documents in a cloud like dropbox or google drive and I want that these data are available and visible to someone looking my site. is it possible? (My intention...

AWS Instance Type For 3,000+/Second Outgoing HTTP Requests?

I'm currently scaling up an application on AWS, we send thousands of outgoing HTTP requests per second to 3rd party API's and services. Are there any EC2 instances optimized for this type of work?

In Spark, does the filter function turn the data into tuples?

Just wondering does the filter turn the data into tuples? For example val filesLines = sc.textFile("file.txt") val split_lines =";")) val filteredData = split_lines.filter(x => x(4)=="Blue") //from here if we wanted to map the data would it be using tuple format ie. x._3 OR x(3) val blueRecords = =>...