FAQ Database Discussion Community


How to install phpmyadmin on Ubuntu 14.04 by ansible?

phpmyadmin,ubuntu-14.04,ansible,ansible-playbook
I want to install phpmyadmin on ubuntu 14.04 with ansible. I don't know how to answer in installation questions with ansible playbook!! I search a lot in this site and other sites but i found nothing !! Can anyone help?...

recommended way to configure a centos-7 host with static network settings via ansible?

ansible,ansible-playbook,centos7,rhel7
I'm new to ansible and a little googling hasn't lead me quickly towards the right solution to my question. What's the 'with the grain' way to assign static network settings to a centos-7 host with ansible. I feel like this must be a pretty common need -- and there must...

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

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

Cannot copy a directory with Ansible copy module

ansible,ansible-playbook
I been trying to copy a directory (in Linux) to a remote Windows node. I can copy single files without any issue. But when I been trying to copy a directory getting the following error. Environment: Windows 7 Command: ansible --verbose Windows -m copy -a "src=~/Releases dest=C:\Ansible" Error: 10.8.0.4 |...

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

Ansible run task multiple times based on groups

ansible,ansible-playbook
How do you run a task on each group, not just once for the groups? I was excepting the Run this on each host tasks would run once for each group_var value. Instead it seems to just be picking one and running it. I plan on breaking these across multiple...

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

Using 'creates' arg in Ansible shell module

ansible,ansible-playbook
When using the "creates" argument in the shell module, can this be a path to a directory? Or does it have to be a file?

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

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

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

default subnets error for Elasticache creation using Ansible

amazon-web-services,boto,ansible,ansible-playbook,amazon-elasticache
I am trying to create an elastic cache cluster using Ansible. I have a default subnet group already created in my VPC. After executing the below script I am getting an error of default subnet group not being present. - name: Creating Elastic Cache Queue local_action: module: elasticache region: us-east-1...

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

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

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

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

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

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

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

Idempotency in ansible playbook

ansible,ansible-playbook,idempotent
I am configuring a server using Ansible playbook. My playbook works properly at the very first execution but when I run the same playbook again it creates the duplicates lines in the configuration file on the server. I am using lineinfile module. Example following task adds the line each time...

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

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

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

ansible jinja2 concatenate IP addresses

jinja2,ansible,ansible-playbook
I would like to cocatenate a group of ips into a string. example ip1:2181,ip2:2181,ip3:2181,etc {% for host in groups['zookeeper'] %} {{ hostvars[host]['ansible_eth0']['ipv4']['address'] }} {% endfor %} I have the above code, but can't seem to quite figure out how to concatenate into a string. searching for "Jinja2 concatenate" doesn't give...

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

Include tasks in file before the file exists

ansible,ansible-playbook
I have an Ansible playbook that includes two other files: - include: myFile1.yml - include: myRepo/myFile2.yml The problem is that myRepo is a git repository checked out by one of the tasks in myFile1.yml, so myFile2.yml doesn't exists unless the tasks in myFile.yml complete successfully. Ansible has a problem with...

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

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

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

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

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 i can access gtm shell with ansible playbook command

ansible,ansible-playbook
I am stuck at this,I could easily set source for GT.M but after this, when I fire gtm command it get stuck,don't get out of it also,somebody please help me out. my code is as follow: --- - name: Copying files on local machine and printing Hello msg. hosts: webservers...

a newbee trying to use ansible and a weird error

ansible,ansible-playbook
I have this playbook: - name: main playbook hosts: 127.0.0.1 connection: local sudo: Yes gather_facts: True vars_files: - /home/core/REPO/alonso/core2door-integration/workflows/core2door.ansible/vars-feed.yml tasks: - include: tasks/feed-adapter.yml tasks/feed-adapter.yml # This playbook deploys feed-adapter application in this host. This app needs a jar that basically writes to HDFS and write a log in a system,...

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

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

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

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

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

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

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

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

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

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

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

Ansible copy fails

ansible,ansible-playbook,winrm
I was trying to copy a test file from a Linux control server to a Windows 7 client. my playbook is - name: Test Copy from Linux to Windows hosts: Windows gather_facts: false tasks: - name: Copy copy: src=/tmp/tmp.txt dest=C:\Ansible And getting this error failed: [10.8.0.4] => {"failed": true, "md5sum":...

I have a ansible file . I just want to run ansible file in flask API

python-2.7,flask,ansible-playbook
I have one ansible file : hosts: all user: vagrant sudo: true tasks: - user: name=pape shell=/bin/bash groups=admin append=yes sudo: true - name: Creates directory file: path=/home/pape/.ssh state=directory owner=pape group=pape mode=0700 sudo: true - name: Make sure that the /home/{{createuser}} directory exsists action: file path=/home/james/.ssh state=directory - name: Setup |...

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 can't get inventory_hostname

jinja2,ansible,ansible-playbook
I'm trying to get the short name of a server being worked on. I have this in jinja2: ServerAlias graphite.{{ hostvars[inventory_hostname] }} ServerAlias graphite.{{ hostvars[inventory_hostname] }}.{{dc}}.{{subnet}} The above just spills the whole glob of facts instead of just the short name. This is what the hosts.yaml looks like: graphite.experimental.com dc=lv1...

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

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

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

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

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

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

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

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

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

about ansible, Permission denied when trying to execute a script

ansible,ansible-playbook
i am newbee with ansible, so i am getting an error when trying to run my own playbook. My playbook fails with this action: # run check-feed-adapter-folders script. the script tries to create some folders on HDFS. - command: "{{check_feed_adapter_folders_outputpath}}/check.sh" This is the output of the ansible-playbook command: TASK: [command...

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