ansible-playbook

How can i run ansible command if certain file changed

若如初见. 提交于 2019-12-21 12:10:09
问题 I am using ansible to deploy my django App using - name: Upgrade the virtualenv. pip: requirements={{project_root}}/www/requirements.txt virtualenv={{project_root}}/www/virtualenv But i only want to run that if requirements.txt changed since last run 回答1: We need to determine if any of the requirement files have changed. The steps are as follows: Touch the temp requirement files. (If they didn't exist, the md5 will be different for the new blank file) Calculate the md5 hash of the previous

How to delete *.web files only if they exist

痴心易碎 提交于 2019-12-21 09:38:14
问题 I need to create an Ansible playbook to delete the *.web files in a specific directory only if the files exists. OS : cent OS, Redhat 5x, 6x. I have tried the following with no success: - stat: path=/opt/app/jboss/configuration/*.web register: web - shell: rm -rf /opt/app/jboss/configuration/*.web when: web.stat.exists 回答1: @bruce-p's answer gives a deprecation warning with Ansible 2.0+, but the new with_fileglob gives another option: - file: path={{ item }} state=absent with_fileglob: /opt

How to delete *.web files only if they exist

好久不见. 提交于 2019-12-21 09:38:05
问题 I need to create an Ansible playbook to delete the *.web files in a specific directory only if the files exists. OS : cent OS, Redhat 5x, 6x. I have tried the following with no success: - stat: path=/opt/app/jboss/configuration/*.web register: web - shell: rm -rf /opt/app/jboss/configuration/*.web when: web.stat.exists 回答1: @bruce-p's answer gives a deprecation warning with Ansible 2.0+, but the new with_fileglob gives another option: - file: path={{ item }} state=absent with_fileglob: /opt

Ansible: variable interpolation in task name

旧巷老猫 提交于 2019-12-21 07:06:33
问题 I cannot get this seemingly simple example to work in Ansible 1.8.3. The variable interpolation does not kick in the task name. All examples I have seen seem to suggest this should work. Given that the variable is defined in the vars section I expected the task name to print the value of the variable. Why doesn't this work? Even the example from the Ansible documentation seems to not print the variable value. --- - hosts: 127.0.0.1 gather_facts: no vars: vhost: "foo" tasks: - name: create a

Add multiple SSH keys using ansible

主宰稳场 提交于 2019-12-21 04:42:55
问题 I have written an ansible script to remove SSH keys from remote servers: --- - name: "Add keys to the authorized_keys of the user ubuntu" user: ubuntu hosts: www tasks: - name: "Remove key #1" authorized_key: user=ubuntu key="{{ item }}" state=absent with_file: - id_rsa_number_one.pub - name: "Remove key #2" authorized_key: user=ubuntu key="{{ item }}" state=absent with_file: - id_rsa_number_two.pub ... Adding each file as a different task is preposterous, so I have tried using with_fileglob:

Having trouble provisioning EC2 instances using Ansible

送分小仙女□ 提交于 2019-12-21 02:43:33
问题 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 make most sense, so I run it using: ansible-playbook launch-ec2.yaml -i ec2.py which gives me: msg:

Ansible: how to run a play with hosts with different passwords?

拜拜、爱过 提交于 2019-12-20 19:57:27
问题 I'm currently learning how to use Ansible. Right now, I've got a bunch of servers, both new and legacy, that have different logins or passwords or both. All have key access to run the plays. Here's what I started with. Example hosts file: # legacy and new have different logins (like root and deploy) [legacy] serv1 serv2 [new] serv3 serv4 # different has a different login and password altogether [different] serv5 So to keep things simple, I originally had a playbook run the equivalent of sudo

Proper way to concatenate variable strings

北城余情 提交于 2019-12-20 10:22:48
问题 I need to create new variable from contents of other variables. Currently I'm using something like this: - command: echo "{{ var1 }}-{{ var2 }}-{{ var3 }}" register: newvar The problem is: Usage of {{ var1 }}...{{ varN }} brings too long strings and very ugly code. Usage of {{ newvar.stdout }} a bit better but confusing. Usage of set_fact module caches fact between runs. It isn't appropriate for me. Is there any other solution? 回答1: Good question. But I think there is no good answer which

How to get current role name in an ansible task

本小妞迷上赌 提交于 2019-12-20 10:01:11
问题 How can I get the current role name in an ansible task yaml file? I would like to do something like this --- # role/some-role-name/tasks/main.yml - name: Create a directory which is called like the current role name action: file path=/tmp/"{{ role_name }}" mode=0755 state=directory The result of this task should be a directory /tmp/some-role-name on the server 回答1: As of Ansible 2.2 : {{role_name}} As of Ansible 2.1 : {{role_path|basename}} Older versions: There is no way to do this in the

How to get current role name in an ansible task

一曲冷凌霜 提交于 2019-12-20 10:01:10
问题 How can I get the current role name in an ansible task yaml file? I would like to do something like this --- # role/some-role-name/tasks/main.yml - name: Create a directory which is called like the current role name action: file path=/tmp/"{{ role_name }}" mode=0755 state=directory The result of this task should be a directory /tmp/some-role-name on the server 回答1: As of Ansible 2.2 : {{role_name}} As of Ansible 2.1 : {{role_path|basename}} Older versions: There is no way to do this in the