FAQ Database Discussion Community


Ansible mysql_user priv - “invalid privileges string: Invalid privileges specified”

ansible
I'm using the mysql_user module to attempt to add a user and privileges. I'm getting an "invalid privileges string" error on the following task. - name: Add api user mysql_user: name="user_name" host="{{ item }}" password={{ mysql_password }} priv={{ mysql_project_database }}.console_users:"SELECT (col_one, col_two)" with_items: - "%" tags: - mysql-user I'm running...

Ansible - conditionally include a file in a role

ansible,ansible-playbook
I'm trying to craft a role that will run only if a variable gets registered is of a certain value, in this case, the md5sum of a file. The role/main.yml looks like this: ---- - name: Has this already been done? Check for the script, & it's md5sum command: md5sum...

Case statement for setting var in Ansible/Jinja2

jinja2,ansible,ansible-playbook
I'm using Ansible with Jinja2 templates, and this is a scenario that I can't find a solution for in Ansible's documentation or googling around for Jinja2 examples. Here's the logic that I want to achieve in Ansible: if {{ existing_ansible_var }} == "string1" new_ansible_var = "a" else if {{ existing_ansible_var...

Ansible Dynamic Inventory: Auto-incrementing Integer Assignment to Hostvars

amazon-ec2,ansible
I have a list of three hosts in a dynamic inventory (ec2.py). I want to assign an auto-incrementing integer to a hostvar of each. For example, the first EC2 instance would get a hostvar foo=1, the second would get foo=2, and the third foo=3. Does anyone have any idea how...

Ansible git module not checking out a branch

git,ansible
I'm using ansible to checkout my webapplication on EC2 web instances. My code is as followed: - name: Checkout the source code git: accept_hostkey=yes depth=5 dest={{ webapp_dir }} force=yes key_file=/var/tmp/webapp_deploy_key [email protected]:MyRepo/web-app.git update=yes version={{ webapp_version }} register: git_output As long as webapp_version = masterit works perfectly. But as soon as I...

Retrying ansible playbook with Vagrant

vagrant,ansible,ansible-playbook,vagrantfile
Is there any way to retry playbooks playbooks from where they failed? I'm starting it with vagrant provision Thanks...

Multiple ansible conditionals no longer work with version 1.9

conditional-statements,ansible
I have the following task file in one of my roles: - name: check for initalized fixtures stat: path={{ fixture_init_file }} register: fixture_init - name: copy fixtures copy: src={{ fixture_file }} dest={{ fixture_dest }} when: fixture_init.stat.exists == False - name: debug debug: var=fixture_init - name: db2 debug: var=database - name:...

How can I add/remove instances from GCE load balancers with Ansible?

google-compute-engine,ansible,google-cloud-platform
I see that there is a gce_lb Ansible module, but it is unclear to me whether or not I can actually use this to change the instances assigned to that LB or whether the module just creates and destroys LBs. In contrast, EC2 clearly has one module just for creating...

Can I set remote_user in host_vars or group_vars?

ansible,ansible-playbook
I'm starting to write my first serious playbook in ansible. Something I'd like to do is to specify different remote_user values per host. I'm able to set remote_user in ansible.cfg, through the CLI -u option and even in play variables, like so: --- - name: install dependencies hosts: all sudo:...

Ansible - find the maximum value of a hostvar and the name of that host [closed]

amazon-ec2,ansible
I have an inventory with a hostvar that increases: [nodes] node_0 id=0 node_1 id=1 I want to find the highest value of id and host that has it. I found another answer for doing the search on nodes with a for loop (Ansible - Find max value and run action...

Ansible - Switch config file in task

nginx,config,ansible
So I'm basically trying to load the config files through an task so in the first part of the task it would use the configuration variables for domain 1 for example with the nginx vhost file and the second part it would use the configuration variables for domain 2 which...

Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”

postgresql,ansible
I am provisioning a 'Precise64' Ubuntu machine via Ansible, I am encountering an error when ensuring that the database is in fact created. I am using most of https://github.com/jcalazan/ansible-django-stack - name: Install PostgreSQL apt: name={{ item }} update_cache={{ update_apt_cache }} state=installed with_items: - postgresql - postgresql-contrib - python-psycopg2 tags: packages...

Ansible inventory parameters for pem key

osx,ansible
I'm just getting started with Ansible but I'm running into various issues. The latest is my ssh keys aren't being picked up by the 'hosts' inventory file. The file's contents are: [my host] my-dev ansible_ssh_host=54.79.31.51 ansible_ssh_private_key_file=/Users/dev/.ssh/dev.pem ansible_ssh_user=ec2-user And the error I get when executing ansible all -m ping -vvvv <54.79.31.51>...

Ansible write variables into YAML file

python,yaml,jinja2,ansible
I have a specific ansible variable structure that I want to get from the vault into a yaml file on my hosts. Lets assume a structure like this: secrets: psp1: username: this password: that secret_key: 123 ... I need something like a "generic" template to output whatever "secrets" contains at...

Ansible condition always evaluates to false

ansible,ansible-playbook
I'm trying to examine the output of a shell command for a particular string which indicates an error, and that the playbook should be terminated. I'm trying to debug it something like this: - debug: var=foo_result - debug: msg={{ 'Some error text' in foo_result }} In this example, install_result was...

Ansible and s3 module

amazon-web-services,amazon-s3,ansible,ansible-playbook
I'm trying to use Ansible to download some files to my various EC2 instances. The problem I'm having is when it comes to my AWS credentials. The AWS Ansible modules all work great, including the S3 module. The following (when I substitute in my AWS credentials) works like a charm....

ansible playbook role variable

ansible,ansible-playbook
fairly new to ansible. having following role e.g.: my-role - i have trouble overriding the default variables from the playbook follwing files: my-role/tasks/main.yml my-role/defaults/main.yml sample-playbook.yml my-role/tasks/main.yml - name: "Add Test User" user: name={{ my_config_test_user }} comment="{{ my_config_test_user }}" group={{ my_config_test_user }} my-role/defaults/main.yml my_config_test_user: "test" playbook: - name: TestCase hosts: all...

Running bash commands in Ansible task

python,mysql,ansible,ansible-playbook
I am porting a Makefile into a series of Ansible tasks. The make file has these two lines of code which are troubling me when it comes to ansible: SERVERS := shell mysql "select hostname from servers" EASY_INSTALL := wget https://bootstrap.pypa.io/ez_setup.py -O - | python Firstly, what's the appropriate Ansible...

How to reboot CentOS 7 with Ansible?

centos,ansible,centos7
I'm trying to reboot server running CentOS 7 on VirtualBox. I use this task: - name: Restart server command: /sbin/reboot async: 0 poll: 0 ignore_errors: true Server is rebooted, but I get this error: TASK: [common | Restart server] *********************************************** fatal: [rolcabox] => SSH Error: Shared connection to 127.0.0.1 closed....

How to add a disk to a Google Compute Engine instance with the gce_pd Ansible module?

google-compute-engine,ansible,ansible-playbook
I'm new to Ansible, but I have a working playbook that creates Google Compute Engine instances. I followed the Ansible section of Compute Engine Management with Puppet, Chef, Salt, and Ansible - Appendix to achieve this. Now I would like to extend the playbook to add extra persistent disks to...

how to read each element of an yaml map

yaml,ansible
I am trying to access all the elements of a yaml object, any suggestions would be helpful: object: element1: "value1" element2: "value2" element3: "value3" The above object is defined in group_vars/all file so that it can be accessed by other tasks. - name: pass values to script debug: "msg={{ item...

default value for dictionary in jinja2 (ansible)

jinja2,ansible
jinja2 has filter '|default()' to works with undefined variables. But it does not work with dictionary values. if D may have or not have key foo (D[foo]), than: {{ D[foo]|default ('no foo') }} will prints 'no foo' if D is undefined, but will cause error ('dict object' has no attribute...

ansible-galaxy install fails when specifying a version in requirements

ansible
Not sure if this is a bug in ansible-galaxy, but I'm trying to install roles from a requirements.yml file (related ansible documentation.) One of those roles is being pulled from git, with a specific version like so: requirements.yml: --- - src: https://github.com/thom-nic/ansible-shell name: thom-nic.shell version: develop When I run ansible-galaxy...

Recover ansible-vault password in case password is forgotten

ansible
I am using ansible-vault to set password protect var/main.yml file. Now I can push my source code in source control system. After that deploys in production server. Suppose somebody manipulate the password or forgot the password. Is there any way to recover ansible-vault password or set the new password again...

How do I make Ansible ignore failed tarball extraction?

ansible,ansible-playbook
I have a command in an ansible playbook: - name: extract the tarball command: tar --ignore-command-error -xvkf release.tar It is expected that some files won't be extracted as they exist already (-k flag). However, this results in ansible stopping the overall playbook as there is an error code from the...

Ansible use task return varible in variable templates

ansible,ansible-playbook
I am trying to craft a list of environment variables to use in tasks that may have slightly different path on each host due to version differences. For example, /some/common/path/v_123/rest/of/path I created a list of these variables in variables.yml file that gets imported via roles. roles/somerole/varables/main.yml contains the following somename:...

Manage whole crontab files in Ansible

cron,ansible
I have a crontab containing around 80 entries on a server. And I would like to manage that crontab using Ansible. Ideally I would copy the server's crontab to my Ansible directory and create an Ansible task to ensure that crontab is set on the server. But the cron module...

ANSIBLE Windows winrm 401

windows,ansible,winrm
I follow the instructions on Ansible website, but I'm still facing an issue with a simple "win_ping" command when i try to communicate with a windows node: Ansible Version : 1.8.2 Windows machine OS : Windows Server 2012 Standard Powershell : v3.0 the error I got: [[email protected] group_vars]# ansible windows...

Save temporary ansible shell scripts instead of deleting

ansible,ansible-playbook
I noticed Ansible removes the temporary script using a semi-colon to separate the bash commands. Here is an example command: EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/devuser/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 build /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python...

how to deal with unverified apt install in ansible

ansible,apt-get,apt,ansible-playbook
when installing an apt package from our own repo, I get the the following on the CLI: Install these packages without verification? [y/N] The question is, how does one install these packages successfully using ansible? Even with the force option, ansible fails to install the package. The command I'm using...

Passing values dynamically to an Ansible inventory - Python

python,ansible
I'm trying to Ansible's Python API in order to write a test API (in Python) which can take advantage of a playbook programmatically and add new nodes to a Hadoop cluster. As we know, at least node in the cluster has to be the Namenode and JobTracker (MRv1). For simplicity...

Pass a file glob to an Ansible role

ansible
I'm trying to pass a list of file paths to a role, so that it can process them using with_items. The use case is having a generic role (logstash) that can be given a set of configuration files, which it'll place in the right directory on the host. Role use...

How to conditionally check the state of an openstack instance

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...

ansible ssh prompt known_hosts issue

ssh,command-prompt,ansible,ansible-playbook,hosts-file
I'm running Ansible playbook and it works fine on one machine. On a new machine when I try for the first time, I get the following error. 17:04:34 PLAY [appservers] ************************************************************* 17:04:34 17:04:34 GATHERING FACTS *************************************************************** 17:04:34 fatal: [server02.cit.product-ref.dev] => {'msg': "FAILED: (22, 'Invalid argument')", 'failed': True} 17:04:34 fatal: [server01.cit.product-ref.dev]...

In a vagrant/ansible set up, who is responsible for starting servers (nodejs, rails)

vagrant,chef,ansible
Our infrastructure is getting pretty complex with many moving pieces so I'm setting up Vagrant with Ansible to spin up development environments. My question is who (Vagrant or Ansible or another tool) should be responsible for starting various such as rails s (for starting rails server) nginx nodejs (for seperate...

Ansible define a custom service path and notify only if the service is restarted

ansible,ansible-playbook
I'm working on a new opsware agent service check on AIX, its agent path is /etc/rc.d/init.d/opsware-agent. Firstly please let me know how to define this variable path and call in service. Secondly it should run the command only if this opsware agent service has been restarted. How to do it,...

Ansible-pull with no inventory limitations

ansible,ansible-playbook
I want to have a set of git repos with base application config playbooks in them such that all I need to do with any VM, regardless of its name or role or how long its been around, to get the base config installed is to run an ansible-pull command...

Ansible: Conditional check to either output name of child group or individual host based on specified limit

ansible,ansible-playbook
Hi to all friendly automagicians, I'm using ansible in order to administrate tasks on a heap of embedded linux nodes that are rapidly expanding. Since our project is using hipchat, I figured it's necessary to start notifying to a room so I don't keep annoying researchers by rebooting or something...

How to use Erlang configuration files with Python J2 template?

python,jinja2,ansible
I would like to deploy with Ansible some configuration files the following way: - name: Deploying test configuration template: src={{ item }}.j2 dest={{ basho_bench_home_dir }}/conf/{{ item }} sudo: yes with_items: - http_fix_1min.conf.template - http_max_1min.conf The files have lines like these: {mode, max}. {duration, 1}. {concurrent, 32}. This ultimately breaks the...

How to make Ansible YAML parsing accept this command?

yaml,ansible,ansible-playbook
Question: How to make Ansible YAML parsing accept this command ? Details below: This YAML: -shell: "/home/developer/eclipse/eclipse -application org.eclipse.equinox.p2.director -noSplash -repository 'http://moreunit.sourceforge.net/update-site' -installIUs org.moreunit.feature.group" is validated by: http://yaml-online-parser.appspot.com/ http://www.yamllint.com/ http://codebeautify.org/yaml-validator but ansible says: This one looks easy to fix. It seems that there is a value started with a quote,...

Process item in Ansible loop only if condition is met and restarting SSH service in Ansible Playbook

ssh,firewall,ansible,ansible-playbook
I have few simple tasks in Ansible playbook: tasks: - name: Reset firewall action: shell ufw --force reset - name: Manage firewall ports ufw: rule=allow port={{ item }} proto=tcp with_items: - "{{ ssh_port }}" - "{{ 80 if myvar == 'yes' else '' }}" - "{{ 8080 if myvar ==...

Ansible - Mode 755 for directories and 644 for files recursively

file-permissions,ansible
I'd like to allow anyone to list and read all files in my directory tree, but I don't want to make the files executable : dir \subdir1 file1 \subdir2 file2 ... \subdirX fileX The following task makes my directories and files readable, but it makes all the files executable as...

how to speed up ansible?

dns,ansible
We've implemented ansible recently. Somehow, we found it really slow, and wonder how to speed up. So, I did some stracing, found /etc/resolv.conf and /etc/hosts related, then seemed to be the reverse DNS issue as follow: 18:32:13.961094 IP 192.168.22.2.44206 > 192.168.23.2.53: 12243+ PTR? xxx.xxx.29.115.in-addr.arpa. (45) 18:32:18.966199 IP 192.168.22.2.44206 > 192.168.23.2.53:...

Ansible Tower: Send e-mail if the project failed

ansible,ansible-playbook
I would like to get a e-mail when the project failed. So I've created a task at the end of the file wich sends me an e-mail. The problem is now that when a task failed also the hole project failed and the e-mail task wouldn't triggered. Can somebody help...

Only check whether a line present in a file (ansible)

ansible,ansible-playbook
I need to check whether a particular line present in a file or not in ansible. Basically I need to convert following command to ansible task. My goal is to only check. grep -Fxq "127.0.0.1" /tmp/my.conf ...

Terminate ansible playbook based on shell output

ansible,ansible-playbook
I have an ansible playbook that runs a shell command. If there is a specific message in the output, I need to terminate the playbook. Here's what I've tried: - name : Do foo shell: /bin/my_application arg1 arg2 arg3 args: creates: /tmp/foo_1 with_items: data_items register: foo_result - debug: var=foo_result -...

Ansible Role to Check Health of a host group

ansible
After running several plays in my playbook, I want to verify the deployment of my apps. In one of my roles, I have the following task, adds created ec2 instances to hosts as 'launched': - name: Add new instance to host group local_action: add_host hostname={{ item.public_ip }} groupname=launched with_items: ec2.instances...

`with_dict expects a dict` - Ansible global composer and kosssi.composer

php,composer-php,ansible,kosssi-composer
I'm trying to use the kosssi.composer Ansible role to install a global composer instance as well as a couple of composer packages. --- - hosts: myhosts remote_user: vagrant sudo: true roles: - { role: kosssi.composer, composer_path_env: true, composer_home_path: /opt/composer, composer_home_owner: vagrant, composer_home_group: vagrant, composer_global_packages: phpunit/phpunit: '@stable' phing/phing: '@stable' } I've...

ansible local file path for unarchive

ansible,ansible-playbook
I have what I think is a fairly common task of taking a local archive file, transferring it to a server, and extracting it there. I'm using the unarchive module for this but struggling with an elegant way to deal with the local filename always being different because the filename...

How to run a shell command in ansible's check mode?

git,shell,ansible
In check mode, I want to display the current commit in the server. I'm using the shell command (git rev-parse HEAD) to register the variable and then print/debug it but ansible skips shell commands in check mode. Is there anyway to mark a shell command as safe to run in...

How to use Ansible to automate one-off tasks?

shell,path,ansible,ansible-playbook
I'm using Ansible to automate VM configuration for some of our build environments, e.g. setting up the PATH and proxy environment variables, installing global Node.js tools, etc. This works great, and it's easy to automate common setup tasks over multiple hosts. All of the tasks are split up over Ansible...

Remove a rule from AWS EC2 Security group using Ansible

amazon-web-services,amazon-ec2,ansible,ansible-playbook
I have an Ansible script to create EC2 security group. It looks like this: - name: Create HTTP Security Group local_action: module: ec2_group region: "{{ region }}" vpc_id: "{{ vpc }}" name: sg_http description: Security group for HTTP access rules: - proto: tcp from_port: 80 to_port: 80 cidr_ip: 0.0.0.0/0 register:...

Combine two default Ansible host files including one being ec2.py?

ansible,ansible-playbook
I'm using Ansible is a mixed environment of AWS and non-AWS machines. I'd like to avoid passing hosts on the command line. How do I combine multiple host files in Ansible and make it the default? The current recommendation on the Ansible site is to override /etc/ansible/hosts with ec2.py. which...

how to deal with percona keyserver with ansible

ansible,apt,percona
I have been trying to create a percona role in ansible and failing at it. I won't really say failing but it doesn't work as planned. Below is a snippet of the role - name: Setting up percona server apt-key apt_key: id=1C4CBDCDCD2EFD2A keyserver=keys.gnupg.net state=present Upon running this I ended up...

Ansible variable name `environment` is reserved?

ansible
I've got a strange situation today. I called one of my variables in a playbook environment. If I dump variables using debug instruction, it is shown ok "environment": "development", But if I try to access it from a script using {{ environment }} it is always assigned a value of...

Remove package ansible playbook

amazon-ec2,vagrant,ansible,ansible-playbook
I've an EC2 instance create using Vagrant and provisioned with Ansible. I've this task that install 2 package using apt. --- - name: Install GIT & TIG action: apt pkg={{ item }} state=installed with_items: - git - tig I want now delete/remove tig from my instance. I've removed it from...

How To Achieve Python3.4 Virtualenv For Precise64 VirtualBox

django,virtual-machine,ubuntu-12.04,ansible,python-3.4
I'm trying to create virtualbox using precise64, Vagrant, and Ansible. I am able to get python2.7 virtualenv setup, but would like to use python3.4 instead. I cloned the ansible-django-stack repository and everything works, but it is using version 2.7. What should I change in order to get a python3.4 Virtualenv...

How to run a task when variable is undefined in ansible?

ansible,ansible-playbook
I am looking for a way to perform a task when ansible variable is not registers /undefined e.g -- name: some task command: sed -n '5p' "{{app.dirs.includes}}/BUILD.info" | awk '{print $2}' when: (! deployed_revision) AND ( !deployed_revision.stdout ) register: deployed_revision ...

Ansible - msg: No package matching '$item' is available

ansible,ansible-playbook
I need to set-up my server. I've the following ansible playbook. --- - hosts: webservers user: root sudo: yes tasks: - name: add nginx ppa action: apt_repository repo=ppa:nginx/stable state=present - name: install common packages needed for python application development action: apt pkg=$item state=installed with_items: - libpq-dev - libmysqlclient-dev - libxml2-dev...

Create and access dict in Ansible playbook

ansible,ansible-playbook
I'm trying to set a variable in an Ansible playbook based on an existing variable's value which could be one of many different strings. It's basically a case/switch statement and this is the logic (with incorrect syntax): if {{ existing_ansible_var }} == "string1" new_ansible_var = "a" else if {{ existing_ansible_var...

One loop over multiple Ansible tasks

loops,ansible,ansible-playbook
I've created an Ansible playbook that creates a cloud instance and then installs some programs on the instance. I want to run this playbook multiple times (without using a bash script). Is it possible to use a loop to loop over those two tasks together (I.E. One loop for two...

Having trouble provisioning EC2 instances using Ansible

ansible,ansible-playbook
I'm very confused on how you are supposed to launch EC2 instances using Ansible. I'm trying to use the ec2.py inventory scripts. I'm not sure which one is supposed to be used, because there is three installed with Ansible: ansible/lib/ansible/module_utils/ec2.py ansible/lib/ansible/modules/core/cloud/amazon/ec2.py ansible/plugins/inventory/ec2.py I thought running the one in inventory/ would...

Custom ansible module in python - How to resolve relative role file paths?

python,ansible
I'm writing a new custom ansible module in python. I want to be able to resolve paths in my code (in order to read their content) just as "file" and "copy" modules do when receiving a relative path in "src" argument (the path is relative to root-dir/roles/x/files), for instance. Is...

Error on ansible-playbook on simple apache2 task

apache,ansible
Trying my hands on ansible with a small orchestration but quickly run in to issue on a simple apache issue. At the point of restarting after enabling mod_proxy, it fails with : ~$ ansible-playbook ansible/playbooks/apache_tomcat_mysql_mongo_stack.yml -u ansible --private-key ~/ansible/ansible.pem PLAY [web] ******************************************************************** GATHERING FACTS *************************************************************** ok: [192.168.56.103] TASK: [apache |...

How do you provide domain credentials to ansible's mount module?

ansible,ansible-playbook
I've figured out how to use the shell module to create a mount on the network using the following command: - name: mount image folder share shell: "mount -t cifs -o domain=MY_DOMAIN,username=USER,password=PASSWORD //network_path/folder /local_path/folder sudo_user: root args: executable: /bin/bash But it seems like it's better practice to use Ansible's mount...

Ansible: Access host/group vars from within custom module

python,ansible,ansible-playbook
Is there a way how one can access host/group vars from within a custom written module? I would like to avoid to pass all required vars as module parameters. My module is written in Python and I use the boilerplate. I checked pretty much all available vars but they are...

Openstack Heat & Ansible. VM spinup and App deployment

ansible,openstack
I am spinning up new VM's using openstack heat template and get the IP list of the newly spun up VM's. I am using Ansible scripts for the same. I am able to get the new list of IP's from the heat and I am able to deploy an app...

Ansible command to check the java version in different servers

unix,ansible,ansible-playbook
I am writing a Test case using ansible.There are totally 9 servers in which I need to check whether the installed java version is 1.7.0 or not? If it is less than 1.7.0 then test case should fail. Can anyone help me to write this Test case as I am...

ansible 101: can't ping hosts without sudo

ansible
Day one with ansible, and I'm following the getting started documentation. http://docs.ansible.com/intro_getting_started.html I created the '/etc/ansible/hosts' file with one host. The command 'sudo ansible all -m ping -vvvv' works fine. When I drop the sudo I get... 02.my_first_host.com | FAILED => SSH Error: Permission denied (publickey,gssapi-with-mic,password). while connecting to xx.xx.xx.xx:22...

How to escape the '#' comment character within Ansible lineinfile module?

escaping,yaml,ansible
How can I escape characters in Ansible's lineinfile module? Here's the line I want to insert on the server: EMAIL='[email protected]' # Server notification email address enter only 1 address But when I try the following, Ansible refuses to parse it due to YAML errors: line="EMAIL='{{ email_address }}' # Server notification...

How to break `with_lines` cycle in Ansible?

ansible,ansible-playbook
I would like to use the following handler with Ansible: - name: force ntp update shell: ntpdate {{item}} with_lines: /etc/ntpd.serverlist But I want it to end execution after the first successful execution (the list contains ntpd servers with which you can attempt to sync. One is enough). How would I...

Ansible set_fact across plays

ansible,ansible-playbook
I have to run an ansible playbook to execute the following tasks 1) Calculate date in YYYY_MM_DD format and then use this prefix to download some file from aws to my local machine. The filename is of the following format 2015_06_04_latest_file.csv 2) I have to then create a folder by...

ansible lineinfile module - combine quotes and double quotes

ansible
I am trying to add line that contains both single quotes and double quotes and I am failing to do so for an exhausted hour... vars: line1: "a=\\\"a'b'c\\\"" line2: 'a="a\''b\''c"' tasks: - name: lineinfile test lineinfile: dest=/tmp/tmp line={{item}} with_items: - "{{line1}}" - "{{line2}}" the desired line is a="a'b'c" the content...

Triggering Jenkins to run application tests when GitHub PR is created

git,jenkins,continuous-integration,ansible,continuous-deployment
I am a noob to Jenkins, and I have a Jenkins server that runs an ansible playbook to deploy the app. I would like to be able to have Jenkins run an ansible playbook which runs application python tests when a GitHub pull request is opened. I would then like...

ansible group vars vs extra vars with parameterized include tasks

ansible
I'm seeing a value defined in my group_vars/all where I expect to see the overridden value from my -e @local-vars.yml file. In normal cases, the -e wins as per the documentation, but in this more complex case of using parameterized includes, it seems the -e value is not involved at...

ansible playbook execute in this order: task, role, task, role, task

ansible
Forgive my newbie question, but I would like to execute three tasks and use two roles in a playbook, in the order: task role task role task This is what I have so far (task, role, task): --- - name: Task Role Task hosts: 127.0.0.1 connection: local gather_facts: false pre_tasks:...

How to pass variable that's a dictionary into Ansible Role?

yaml,ansible,ansible-playbook
I want to pass some values into an Ansible role, but I can't find any examples in the docs that show how to pass in a variable that's a dictionary. Here is what I'd like to pass in, but my YAML syntax is off: roles: - { role: postgresql, postgresql_users:...

can roles and tasks exist in the same playbook?

ansible,ansible-playbook
--- # file: main.yml - hosts: fotk remote_user: fakesudo tasks: - name: create a developer user user: name={{ user }} password={{ password }} shell=/bin/bash generate_ssh_key=yes state=present roles: - { role: create_developer_environment, sudo_user: "{{ user }}" } - { role: vim, sudo_user: "{{ user }}" } For some reason the create...

User-customizable Ansible inventory

ansible,ansible-playbook,inventory,playbook
Let's say our product is made of two components - consumer and aggregator. Each installed node has n consumers and 1 aggregator. I want to allow customers to make their own custom configuration of up to X clusters, varying the n of consumers per each cluster. My inventory concept: (...

Ansible random UUID generation

ansible
In my Ansible script, I want to generate UUIDs on the fly and use them later on. Here is my approach: - shell: echo uuidgen with_sequence: count=5 register: uuid_list - uri: url: http://www.myapi.com method: POST body: "{{ item.item.stdout }}" with_items: uuid_list.result However I get the following error: fatal: [localhost] =>...

How to import Python modules for user in Jinja2 template

datetime,jinja2,ansible,ansible-playbook
I want to create a file name by formatting datetime.now(). It is simple enough in Python, but the datetime module needs to be imported. How can I import it for use in a Jinja2 template? For example, in this Ansible task: - name: myTask shell: echo "123" > /tmp/{{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}}.zaz ...

How to run global npm binaries with Ansible

linux,node.js,bash,npm,ansible
I've set my npm global install path with npm config set prefix '~/.npm-packages I've updated my PATH to include this. In ~/.profile I have PATH="$HOME/.npm-packages/bin:$PATH" I have installed gulp with npm install -g gulp, verifying that it exists in ~/.npm-packages/bin/gulp I have verified that it is in my PATH...

Ansible conditional with pattern match using variables

amazon-ec2,ansible,ansible-playbook
I am using Ansible roles to provision AWS EC2 instances, I have created a series of task in ec2 roles which gets execute for each server. - name: Provisioning EC2 instance ec2: region: "{{ region }}" key_name: "{{ key }}" instance_type: "{{ instance_type }}" image: "{{ ami }}" wait: yes...

How can I make sure a new ec2_eip is ready for the next task?

ansible,ansible-playbook
When using ec2_eip to associate or disassociate an ElasticIP, it takes a few seconds for the new IP to become available. But wait_for often fails with a fatal error SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh. How...

Ansible: Do something when package version greater or equals

ssh,ansible
I have a problem with running a task only when the package it requires has the correct version. In my example it is the OpenSSH Server. Only on 6.5 or greater the ed25519 host key can generated. Here my tasks: - name: ensure openssh-server is present apt: pkg: openssh-server state:...

Optimizing Ansible Transport\SSH for Unconventional Networks

networking,optimization,ssh,ansible
I'm wondering how to optimise Ansible to work with a network radically different to one where use cases where Accelerate and default might not necessarily be beneficial. In this scenario I'm not dealing with a virtual network, nor am I dealing with servers. I'm dealing with hundreds of embedded, with...

How to set an Ansible role's variables file relative to the host?

variables,roles,ansible,playbook
Here is the detail of my playbook: Playbook tree ├─ devops | ├─ roles | | ├─ mongodb | | ├─ haproxy | | ├─ monit | | | ├─ vars | | | | └─ main.yml | | | └─ ... | | └─ ... | ├─ hosts |...

Missing SimpleJson Module

python,ansible,ansible-playbook
I have Ansible playbook run against a machine with CentOS release 5.6 (Final). I have simplejson installed in the target machine and the module is importable from the python interpreter. But still my playbooks fails with the below error. Error: ansible requires a json module, none found! I am confirming...

How to abstract roles in ansible

ansible,infrastructure
I have a bunch of services, which are built and deployed with ansible. Each service is managed by it's own team, has separate repository and they are completely independent from each other. I have some ansible roles that are the same in all of services (like installed packages, web servers...

How to diff ansible vault changes?

git,diff,ansible,ansible-vault
I'd like to see the actual git commit changes in the ansible vault file. Is there an easy way how to achieve this?...

Rename roles/rolename/tasks/main.yml to rolename.yml in Ansible

ansible
By default, Ansible looks for the tasks for a role in a main.yml. I have too many main.yml files and I'd like to rename this to rolename.yml or something that is more unique. How can I change Ansible's default behavior to use rolename.yml instead of tasks/main.yml?

Ansible, YAML, and Syntax

python,networking,yaml,ansible,ansible-playbook
I am trying to create an Ansible configuration that will run a playbook and utilize a single variable file to create a single configuration with multiple items. I am trying the following syntax and it is failing. How can I fix this? vars/main.yml --- or1host1: - interface: 1/1 description: or1-servertest...

Ansible variable assigment

variables,increment,roles,ansible,ansible-playbook
I want to run a role 10 times in a playbook and only on the 5th run of that role, I want it to run the second shell cmd from within that role. How can I address that ? Playbook: - name: bla bla hosts: ALL remote_user: root vars: some_variable:...

How to traverse a nested dict structure with Ansible?

yaml,ansible,ansible-playbook
I have the following dict structure variable in an ansible playbook: apache_vhosts: - name: foo server_name: foo.com server_aliases: - a.foo.com - b.foo.com - c.foo.com - name: bar server_name: bar.com server_aliases: - d.bar.com - e.bar.com - f.bar.com I need to create a symlink for each of the server_name and server_aliases domains,...

Ansible git clone as root

ansible
I'm using the following role for Ansible in order to clone a project in my vagrant setup: - name: Clone Repository git: repo: https://login:[email protected]/team/repo.git dest: /home/vagrant/workspace/ accept_hostkey: true The cloning is working as expected, but the main issue is that the directory workspace and all it's content is now owned...

How to list all currently targeted hosts in an Ansible play

ansible,ansible-playbook
I am running an Ansible play and would like to list all the hosts targeted by it. Ansible docs mentions that this is possible, but their method doesn't seem to work with a complex targeted group (targeting like hosts: web_servers:&data_center_primary) I'm sure this is doable, but cant seem to find...

Ansible: Insert line if not exists

ansible,ansible-playbook
I'm trying insert a line in a property file using ansible. I want to add some property if it does not exist, but not replace it if such property already exists in the file. I add to my ansible role - name: add couchbase host to properties lineinfile: dest=/database.properties regexp="^couchbase.host"...

Can I rely on php extensions to be stored in /usr/lib/php5/20121212

php,pear,ansible
I'm creating an ansible role that installs a pear module (pam). I want the role to check if the module is already installed using a creates= clause. This module installs itself in /usr/lib/php5/20121212/pam.so but it feels a bit shaky to rely on that. What is a better way to find...

How to set a variable using dynamic inventory using Ansible

amazon-web-services,amazon-ec2,ansible,ansible-playbook,rds
I am looking for method to set a variable in ansible playbook using inventory information received from dynamic inventory. For example if we have a sample playbook like --- - hosts: localhost connection: local tasks: - set_fact: rds_hostname="{{ rds_mysql }}" #set rds endpoint from ec2.py - debug: var=rds_hostname I am...

Vagrant with ansible stop when meet console questions

mongodb,vagrant,ansible
I'm installing mongo extension for PHP in my vagrant with this task --- - name: Intall MongoDb PHP extension sudo: yes command: "pecl install mongo" - name: Copy mongo extension INI to mods-available folder template: > src=mongodb_extension.ini.j2 dest={{ php_conf_dir }}/mongodb.ini owner=root group root mode=644 - name: Enabling mongo config in...