ansible-playbook

How to create conditional copy in Ansible based on network (subnet) membership

人走茶凉 提交于 2019-12-01 21:41:56
问题 I want to copy one version of a file to a server if it has an interface in a specific subnet, or a different version if it does not have an interface in that subnet. Below is a working, but I think less than optimal solution. I'm hoping there is a better way that meets the following criteria... stays dynamic (use facts, I don't want to have to manually set variables for every server and manually create groups for servers in and not in the subnet) less repetitive (could it be handled in one

create multiple directories using ansible

為{幸葍}努か 提交于 2019-12-01 20:10:32
问题 I want to create multiple directories(test1,test2) with 2 sub directories (/home/test1/bin and /home/test2/conf) similarly for test2. My playbook looks like this : -- - hosts: localhost tasks: - name: Create directory file: path=/home/{{item}}/bin state=directory file: path=/home/{{item}}/conf state=directory with_items: - test1 - test2 However i get the following error: An exception occurred during task execution. The full traceback is: Traceback (most recent call last): File "/root/ansible

how to put the result of an echo command into an ansible variable

丶灬走出姿态 提交于 2019-12-01 19:49:11
问题 I have $MY_VAR set to some value on the remote host, and I want to query it from a playbook (put it's value in an ansible variable), here's what I am seeing : - name: put shell var into ansible var command: echo $MY_VAR register: my_var - debug: var=my_var ok: [192.168.78.10] => { "my_var": { "changed": true, "cmd": [ "echo", "$my_var" ], "delta": "0:00:00.002284", "end": "2014-12-17 18:10:01.097217", "invocation": { "module_args": "echo $my_var", "module_name": "command" }, "rc": 0, "start":

How to create conditional copy in Ansible based on network (subnet) membership

巧了我就是萌 提交于 2019-12-01 19:47:52
I want to copy one version of a file to a server if it has an interface in a specific subnet, or a different version if it does not have an interface in that subnet. Below is a working, but I think less than optimal solution. I'm hoping there is a better way that meets the following criteria... stays dynamic (use facts, I don't want to have to manually set variables for every server and manually create groups for servers in and not in the subnet) less repetitive (could it be handled in one task?) not have to list out every possible interface name (eg. eth0, eth1, ..., bond0, bond1, ... etc)

how to put the result of an echo command into an ansible variable

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 19:33:21
I have $MY_VAR set to some value on the remote host, and I want to query it from a playbook (put it's value in an ansible variable), here's what I am seeing : - name: put shell var into ansible var command: echo $MY_VAR register: my_var - debug: var=my_var ok: [192.168.78.10] => { "my_var": { "changed": true, "cmd": [ "echo", "$my_var" ], "delta": "0:00:00.002284", "end": "2014-12-17 18:10:01.097217", "invocation": { "module_args": "echo $my_var", "module_name": "command" }, "rc": 0, "start": "2014-12-17 18:10:01.094933", "stderr": "", "stdout": "$my_var", "stdout_lines": [ "$my_var" ] } }

How to get environment variables of remote host

放肆的年华 提交于 2019-12-01 15:25:00
问题 I am having problems working with the environment variables of a remote host. For example, when I try {{ lookup('env', 'PATH') }} this returns the path of my guest machine not of the remote host. How to pick up / change environment variables of the remote host? my playbook : --- - name : playbook hosts : webservers gather_facts: yes remote_user: user1 vars: Path: "{{lookup('ansible_env','PATH')}}" roles : - task1 - task2 - task3 that's return the path of my machine not the path of remote host

Ansible delegate and run_once

邮差的信 提交于 2019-12-01 11:53:56
i write one specific roles for local and dev environment that will drop and recreate the database from first server in dbserver group which mostly used as the master database. group_vars/dbserver [dbserver] vagrant1 # master db vagrant2 # slave db after that, if i need to drop the database and also create the database again, basically i just need that command to be run on the first server in the group. - name: drop database mysql_db: name={{ targetdbname }} state=absent when: targetdeploydb == "new" delegate_to: "{{ item }}" with_items: "{{ groups.dbserver }}" run_once: true - name: create

Ansible delegate and run_once

荒凉一梦 提交于 2019-12-01 09:45:13
问题 i write one specific roles for local and dev environment that will drop and recreate the database from first server in dbserver group which mostly used as the master database. group_vars/dbserver [dbserver] vagrant1 # master db vagrant2 # slave db after that, if i need to drop the database and also create the database again, basically i just need that command to be run on the first server in the group. - name: drop database mysql_db: name={{ targetdbname }} state=absent when: targetdeploydb =

How can Ansible “register” in a variable the result of including a playbook?

孤人 提交于 2019-12-01 03:05:31
How can an Ansible playbook register in a variable the result of including another playbook? For example, would the following register the result of executing tasks/foo.yml in result_of_foo ? tasks: - include: tasks/foo.yml - register: result_of_foo How else can Ansible record the result of a task sequence? The short answer is that this can't be done. The register statement is used to store the output of a single task into a variable. The exact contents of the registered variable can vary widely depending on the type of task (for example a shell task will include stdout & stderr output from

how to run a particular task on specific host in ansible

↘锁芯ラ 提交于 2019-12-01 02:22:44
my inventory file's contents - [webservers] x.x.x.x ansible_ssh_user=ubuntu [dbservers] x.x.x.x ansible_ssh_user=ubuntu in my tasks file which is in common role i.e. it will run on both hosts but I want to run a following task on host webservers not in dbservers which is defined in inventory file - name: Install required packages apt: name={{ item }} state=present with_items: - '{{ programs }}' become: yes tags: programs is when module helpful or there is any other way? How could I do this ? udondan If you want to run your role on all hosts but only a single task limited to the webservers