Just practicing with some custom modules. I can't really think of anything useful to write because there are so many already, so I just made a random string generator that can be passed into a variable for other tasks. Here's the output: Here's the modul. This filter can be used similar to the default jinja2 random filter (returning a random item from a sequence of items), but can also generate a random number based on a range. To get a random item from a list.
In my Ansible script, I want to generate UUIDs on the fly and use them later on.
Here is my approach:
However I get the following error:
How can I solve this issue?
In ansible 1.9 there is a new filter : to_uuid , which given a string it will return an ansible domain specific UUID,you can find the usage in here https://docs.ansible.com/playbooks_filters.html#other-useful-filters
Ansible - find the maximum value of a hostvar and the name of that host [closed]
amazon-ec2,ansible
My solution: - name: Find max id host set_fact: id_max_host={{ groups['nodes'] | sort('id' | int) | last }} - name: Find max id set_fact: id_max={{ hostvars[id_max_host]['id'] }} It takes the list of hosts in group nodes, sorts by the hostvar 'id' (which it casts to int, because they're usually strings),.
Can I set remote_user in host_vars or group_vars?
ansible,ansible-playbook
What you are doing appears to be undocumented. Specifically, you have this: vars: remote_user: username when, according to the documentation, it should be like this: remote_user: username The fact that it happened to work when you did it the wrong way is irrelevant. There is some side effect that makes.
Ansible random UUID generation
In ansible 1.9 there is a new filter : to_uuid , which given a string it will return an ansible domain specific UUID,you can find the usage in here https://docs.ansible.com/playbooks_filters.html#other-useful-filters
how to read each element of an yaml map
yaml,ansible
The Solution for the problem was to use with_dict. - name: pass values to script debug: 'msg={{ item.value }}' with_dict: - '{{ object }}' .
ansible playbook execute in this order: task, role, task, role, task
I recommend you create roles for post and pre tasks for you ansible. Your site.yml must be some like this: --- - hosts: localhost remote_user: '{{remote_user}}' sudo: yes gather_facts: false roles: - pre - main_role - post in roles folder you must have three roles, pre, post and main_role. .
ansible lineinfile module - combine quotes and double quotes
line2: a='a'b'c' Anyone who can improve the answer with explanation is more than welcome to do so.
How to run a shell command in ansible's check mode?
git,shell,ansible
Found the answer. You have to add always_run: True to the task.
One loop over multiple Ansible tasks
loops,ansible,ansible-playbook
No that's currently not possible. with_items used to work with the include statement in previous versions of Ansible but was unfortunately dropped. Though it will be brought back in Ansible 2.0, see slide 14/15 of What's New in v2 - AnsibleFest London 2015 You could try to work with the.
how to speed up ansible?
dns,ansible
Thanks to @leucos and @CalleDybedahl, this issue finally leads to ssh gssapi authentication method. After appending 'GSSAPIAuthentication=no' to ssh_args within ansible.cfg, there is no PTR query any more. FYI, we make it in ~/.ssh/config, too, for no GSSAPI Authentication implemented in our environment at all.
Passing values dynamically to an Ansible inventory - Python
python,ansible
This should be as simple as adding one or more of these lines to your script after instantiating your group object and before running your playbook: group.set_variable('foo', 'BAR') .
In a vagrant/ansible set up, who is responsible for starting servers (nodejs, rails)
vagrant,chef,ansible File like an eagle (around the cloud with eaglefiler for mac.
I think the answer you're looking for is Ansible (or another tool). Vagrant has capabilities to run scripts and start services. Once you add a configuration management tool, it should do exactly that. That's part of its job: starting and managing services. You want the same application configuration regardless of.
Ansible-pull with no inventory limitations
ansible,ansible-playbook Roblox lumber tycoon hack (the cheat for mac.
Here is the workflow I use for ansible-pull within my VMs: In the base VM I put a file named hosts at /etc/ansible: # cat /etc/ansible/hosts localhost ansible_connection=local My local.yaml starts with - hosts: localhost gather_facts: yes user: root . Now I can use ansible-pull without specifying a hosts file.
Only check whether a line present in a file (ansible)
ansible,ansible-playbook
- name: Check whether /tmp/my.conf contains '127.0.0.1' command: grep -Fxq '127.0.0.1' /tmp/my.conf register: checkmyconf always_run: True ignore_errors: True changed_when: False - name: Greet the world if /tmp/my.conf contains '127.0.0.1' debug: msg='Hello, world!' when: checkmyconf.rc 0 .
Manage whole crontab files in Ansible
cron,ansible
I managed to find a simple way to do it. I copy the crontab file to the server and then update the crontab with the shell module if the file changed. The crontab task: --- - name: Ensure crontab file is up-to-date. copy: src=tasks/crontab/files/{{ file }} dest={{ home }}/cronfile register:.
Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”
postgresql,ansible
after some debugging, I got it working by installing the language pack so the postgres daemon doesn't complain about the Locale when starting - name: Install Language packages apt: name=language-pack-en update_cache={{ update_apt_cache}} force=yes state=latest tags: packages .
How to pass variable that's a dictionary into Ansible Role?
yaml,ansible,ansible-playbook
I think it should be closer to this: roles: - { role: postgresql, postgresql_users: [ { name: 'dev_user', pass: 'dev_pass', encrypted: 'no' }, { name: 'test_user', pass: 'test_pass', encrypted: 'no' } ], postgresql_databases: ['dev', 'test'], postgresql_user_privileges:[ { name: 'dev_user', db: 'dev', priv: 'ALL' }, { name: 'test_user', db: 'test', priv:.
How to import Python modules for user in Jinja2 template
datetime,jinja2,ansible,ansible-playbook
Ansible already knows about the date/time. - name: myTask shell: echo '123' > /tmp/{{ ansible_date_time.date }}_{{ ansible_date_time.hour }}-{{ ansible_date_time.minute }}-{{ ansible_date_time.second }}.zaz See this page for a list of default systems facts.
`with_dict expects a dict` - Ansible global composer and kosssi.composer
php,composer-php,ansible,kosssi-composer
A dictionary is also known as an associative array. There are two ways to define them in YAML, and you're mixing them up, which confuses the parser. Either write the whole thing in JSON style: - hosts: myhosts remote_user: vagrant sudo: true roles: - { role: kosssi.composer, composer_path_env: true, composer_home_path:.
Ansible conditional with pattern match using variables
amazon-ec2,ansible,ansible-playbook
This should work. Basically, set a flag, no need to use Jinja in when. I'm using set_fact twice but in reality you'd just create the is_nat=false var elsewhere. - set_fact: is_nat=false - set_fact: is_nat=true when: 'nat' in server_name' - name: Add server to inventory add_host: hostname={{ item.public_ip }} groupname={{ host_name.
How to run a task when variable is undefined in ansible?
ansible,ansible-playbook
Ansible User Password
From the ansible docs: If a required variable has not been set, you can skip or fail using Jinja2’s defined test. For example: tasks: - shell: echo 'I've got '{{ foo }}' and am not afraid to use it!' when: foo is defined - fail: msg='Bailing out. this play requires.
Ansible inventory parameters for pem key
osx,ansible
I'm not sure exactly what the issue is but I'm wondering if it might be related to the fact that the host is already in my ~/.ssh/config file. I got around this by simply referring to the host name as it is described in my ~/.ssh/config file. I followed the.
Rename roles/rolename/tasks/main.yml to rolename.yml in Ansible
As Bruce already pointed out this is hardcoded. But I have an issue with this behavior as well, as my IDE displays the filename in the tab and I used to have a bazillion tabs named 'main.yml'. My standard setup is to have two files: main.yml role-name.yml In the main.yml.
can roles and tasks exist in the same playbook?
ansible,ansible-playbook
Actually this should be possible and I remember I did this a few times during testing. Might be something with your version - or the order does matter, so that the tasks will be executed after the roles. I would have posted this as a commend, rather than an answer,.
how to deal with percona keyserver with ansible
ansible,apt,percona
The following command should work for you: - apt_key: url=http://www.percona.com/redir/downloads/RPM-GPG-KEY-percona state=present .
Remove a rule from AWS EC2 Security group using Ansible
amazon-web-services,amazon-ec2,ansible,ansible-playbook
By default, the ec2_groups module will idempotently set the rules specified for any present groups as the purge_rules and purge_rules_egress both default to true. If you had previously had a task to create an EC2 secruity group that looked like: - name: Create HTTP and HTTPS Security Group local_action: module:. Microsoft access 2016 for mac free full version.
Combine two default Ansible host files including one being ec2.py?
ansible,ansible-playbook
You can mix dynamic and static inventory files by creating a directory and dropping ec2.py in it plus your ini formatted inventory list as a separate file. It is mentioned briefly in the docs here. for example: ./inventory/ec2.py ./inventory/additional-hosts ansible-playbook . -i inventory/ Note that any file with the executable.
Can I rely on php extensions to be stored in /usr/lib/php5/20121212
php,pear,ansible
No, it's not safe to make assumptions about the install location. The PHP module API number changes with each PHP major version. For instance, 20121212 is the API number used for PHP 5.5. Additionally, the exact path will change based on configuration. For instance, my PHP 5.5 system stores extensions.
Triggering Jenkins to run application tests when GitHub PR is created
git,jenkins,continuous-integration,ansible,continuous-deployment
This is achievable with Jenkins. Wow 1.12 1 repack. There are 3 main steps to this task: Use the Jenkins GitHub plugin to trigger a build. Use the Jenkins Ansible plugin to execute your ansible playbook during build process. Update GitHub repo with the result. This part is a little more complex since I.
ansible ssh prompt known_hosts issue
ssh,command-prompt,ansible,ansible-playbook,hosts-file
The ansible docs have a section on this. Quoting: Ansible 1.2.1 and later have host key checking enabled by default. If a host is reinstalled and has a different key in ‘known_hosts’, this will result in an error message until corrected. If a host is not initially in ‘known_hosts’ this.
Create and access dict in Ansible playbook
ansible,ansible-playbook
As described in the other question/answer, you can do it like this: vars: myDict: {'string1': 'a', 'string2': 'b'} new_ansible_var: '{{myDict[existing_ansible_var | default('this key does not exist in the dict')] | default(') }}' .
Ansible Role to Check Health of a host group
I'm not quite sure what your problem is, but your verify_deployment role will not work, as you use the inventory_hostname variable instead of item. You should probably write: - name: Validate the deployment. Launched is my dynamically created host group uri: url='https://{{ item }}:8000' with_items: launched .
How to add a disk to a Google Compute Engine instance with the gce_pd Ansible module?
google-compute-engine,ansible,ansible-playbook
Ok, I've discovered that the problem was caused by tabs in the yaml. When I replaced tabs, that existed before the most-indented lines in the gce_pd section, with spaces, the error no longer occurred. I guess, for the purposes of interpreting the yaml, a tab counts as a single whitespace.
Optimizing Ansible TransportSSH for Unconventional Networks
networking,optimization,ssh,ansible
If you are working in a network where the connection might be lost 'during' execution of a play/task then I'm not sure if (read: I don't think) ansible saves the context of execution so often as to recover from such issues. If your network is bad, you should fix that.
Openstack Heat & Ansible. VM spinup and App deployment
ansible,openstack
Cloudwerx data solutions software for mac. One options is to create a dynamic inventory script that will fetch the instance ips from Heat and make them available to Ansible. Consider a Heat template that looks like this: heat_template_version: 2014-10-16 resources: nodes: type: OS::Heat::ResourceGroup properties: count: 3 resource_def: type: node.yaml outputs: nodes: value: {get_attr: [nodes, public_ip]} This.
ansible group vars vs extra vars with parameterized include tasks
First, IMHO this is a bug. You should file this as a Github issue with ansible. Second, I suspect this happens because the include line is parsed earlier, in some buggy waay where the extra vars are not taken into account.
ansible playbook role variable
ansible,ansible-playbook
In the current version of Ansible order of precedence says that the value of my_config_test_user should be override not test so I think you probably have a typo somewhere. Maybe the variable is not spelled correctly? I suggest removing defaults/main.yml temporarily to ensure that you do not get an undefined.
Vagrant with ansible stop when meet console questions
mongodb,vagrant,ansible
You can answer the prompt with yes or yes yes (if you want to reply 'yes') or yes no (if you want to reply no). So, you can make your task like so: - name: Intall MongoDb PHP extension sudo: yes shell: 'yes {{ php_install_mongo }} | pecl install mongo'.
Ansible command to check the java version in different servers
unix,ansible,ansible-playbook
Altough in your question you havn't specified what have you tried, but still You can run a commands like this ansible your_host -m command -a 'java -version' If you need to parse the output of java -version there is a very good script from Glenn Jackman here adapt it to.
Ansible set_fact across plays
ansible,ansible-playbook
Facts are host specific. As the documentation about set_fact says, '[v]ariables [set with set_fact] are set on a host-by-host basis'. Instead, I'd try using run_once as defined in Delegation, rolling updates, and local actions, like this: - hosts: contractsServers tasks: - name: Determine date local_action: shell: date '+%Y_%m_%d' --date='1 days.
How to set a variable using dynamic inventory using Ansible
amazon-web-services,amazon-ec2,ansible,ansible-playbook,rds
I was able to solve my above problem by using something like this set_fact: rds_hostname='{{ groups.rds_mysql[0] }}' Also during my research I found a nice ansible galaxy code which allows you to dump all variables accessible to ansible-playbooks https://galaxy.ansible.com/list#/roles/646 Hope this helps someone :).
How to conditionally check the state of an openstack instance
cloud,state,conditional-statements,ansible,openstack
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:.
How to use Erlang configuration files with Python J2 template?
python,jinja2,ansible
Use {% raw %}/{% endraw %} blocks as Jinja2 documentation suggests. Before you could override Jinja2 evironment settings by placing #jinja2: variable_end_string: [[, variable_start_string: ]] on the first line of a template file so that {{ }} weren't not treated as tags. Ansible devs have disabled this feature because of.
How to escape the '#' comment character within Ansible lineinfile module?
escaping,yaml,ansible
The problem indeed is the # in your string - for whatever reason. Though you can easily prevent the parsing error by using this trick: line='EMAIL='{{ email_address }}' {{ '#' }} Server notification email address enter only 1 address' .
Ansible Generate Random String Numbers
Ansible git clone as root
remote_user: vagrant means that it will ssh into the host as user vagrant. sudo: yes means that before executing each task it will sudo, by default to root. You need to remove sudo: yes.
Retrying ansible playbook with Vagrant
vagrant,ansible,ansible-playbook,vagrantfile
I'm not too sure why you'd want to do this as an Ansible playbook should be idempotent and so re-running the whole thing from the start should be completely fine. That said, if you do have some need for this, Ansible exposes a retry mechanism at the end of a.
How to traverse a nested dict structure with Ansible?
yaml,ansible,ansible-playbook
You can use with_subelements to loop through the server_aliases. The below snippet - name: Add a domain symlinks /tmp for server_name. debug: msg='{{ item.server_name }}' with_items: apache_vhosts - name: Add a domain symlinks /tmp for server_aliases. debug: msg='name - {{ item.0.name }} and serverAlias - {{ item.1 }}' with_subelements: -.
Ansible git module not checking out a branch
git,ansible
And again I will answer one of my own questions. The depth=5 was the killer. Well don't use it if you want to have access to all your different versions ;)
Ansible: Do something when package version greater or equals
ssh,ansible
You can do this in two steps. First register the openssh-server version: - name: Get openssh-server version shell: 'dpkg -s openssh-server | grep '^Version' | sed -re 's/^.*:([0-9]+.[0-9]+).*/1/' register: openssh_version Then create the key if needed: - name: ensure ed25519 host key is present command: ssh-keygen -q -t ed25519 -N.
Case statement for setting var in Ansible/Jinja2
jinja2,ansible,ansible-playbook
If you just want to output a value in your template depending on the value of existing_ansible_var you simply could use a dict and feed it with existing_ansible_var. {{ {'string1': 'a', 'string2': 'b'}[existing_ansible_var] | default(') }} You can define a new variable the same way: {% set new_ansible_var = {'string1':.
Running bash commands in Ansible task
python,mysql,ansible,ansible-playbook
It looks like you are wanting to download a script and then run that as a command against a number of servers. The concept of 'hosts' in an Ansible playbook covers your 'servers' concept - you would need to populate an inventory that Ansible can read for the hosts, or.