ansible-2.x

Additional conditions for tasks inside a block

柔情痞子 提交于 2019-12-02 09:53:12
I'm trying to enclose tasks in the block with some when condition. Also some tasks inside this block have additional conditions. The problem is such tasks (with additional conditions) are skipped. Both block's condition and all additional conditions are true. Below there is a sample play: - block: - set_fact: packages_to_install: "{{ packages_to_install }} + [ '{{ (distrs.stdout | from_json).postgresql }}' ]" - set_fact: packages_to_install: "{{ packages_to_install }} + [ '{{ (distrs.stdout | from_json).webserver }}' ]" when: - server.webserver is defined - server.webserver == true when: -

Ansible: how to solve “sudo: a password is required” error? [duplicate]

。_饼干妹妹 提交于 2019-12-02 00:07:52
This question already has an answer here: How can a user with SSH keys authentication have sudo powers in Ansible? [duplicate] 1 answer I have 9 servers and i am trying to install a package using ansible, i am able to ssh into 5 of the servers using a password and other 4 does not ask any password while ssh'ng into them. However i have copied id_rsa.pub key to all the 9 servers. Now the ansible script is working fine for 5 server but w remaining 4 i am getting the following error message. fatal: [xxx0?]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Connection to xxx0? closed

Ansible not detecting Role default variables in its handler

假装没事ソ 提交于 2019-12-01 23:26:38
Does ansible pass Role Default variables to the Handlers within the same Role? Here's a minimal excerpt of the playbook that has the issue: Role hierarchy - playbook.yml - roles/ - gunicorn/ - defaults/ - main.yml - handlers/ - main.yml - code-checkout/ - tasks/ - main.yml Here's the file contents gunicorn/defaults/main.yml --- gu_log: "/tmp/gunicorn.log" gunicorn/handlers/main.yml --- - name: Clear Gunicorn Log shell: rm {{ gu_log }} finalize/tasks/main.yml --- - name: Test Handlers shell: ls notify: - Restart Gunicorn playbook.yml --- - name: Deploy hosts: webservers tasks: - include: roles

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

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)

Ansible: How to add variables to “command” or “shell”

五迷三道 提交于 2019-12-01 16:36:10
Is it possible to use variables on command or shell modules? I have the following code, and I would like to use variable file to provide some configurations: I would like to read the Hadoop version from my variables file. On other modules of ansible I could use {{ansible_version}} , but with command or shell it doesn't works. - name: start ZooKeeper HA command: hadoop-2.7.1/bin/hdfs zkfc -formatZK -nonInteractive - name: start zkfc shell: hadoop-2.7.1/sbin/hadoop-daemon.sh start zkfc I would like to convert to the following: - name: Iniciar zkfc command: {{ hadoop_version }}/sbin/hadoop-daemon

Ansible: compare variables

眉间皱痕 提交于 2019-12-01 13:40:57
I am trying to compare some variables so here is my case: pg_master_ip is an ip obviously. ansible doesn't parse pg_master_ip . bond0.stdout is a result of an earlier register task. If I could use {{ hostvars[inventory_hostname]['ansible_bond0'].ipv4.address }} I'd be happier but I don't know how. - name: pgsql and pgpool initiate master include: master.yml when: bond0.stdout == '{{pg_master_ip}}' Thank you for the advice in advance. Using {{ hostvars[inventory_hostname][some_variable] }} is redundant. You can just use {{ some_variable }} instead. In this case it would be {{ ansible_bond0.ipv4

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: compare variables

本小妞迷上赌 提交于 2019-12-01 09:47:18
问题 I am trying to compare some variables so here is my case: pg_master_ip is an ip obviously. ansible doesn't parse pg_master_ip . bond0.stdout is a result of an earlier register task. If I could use {{ hostvars[inventory_hostname]['ansible_bond0'].ipv4.address }} I'd be happier but I don't know how. - name: pgsql and pgpool initiate master include: master.yml when: bond0.stdout == '{{pg_master_ip}}' Thank you for the advice in advance. 回答1: Using {{ hostvars[inventory_hostname][some_variable] }

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 =