ansible-inventory

Adding hosts to Ansible host file

谁说胖子不能爱 提交于 2019-12-08 08:17:01
问题 I have been trying to add a host name to my hosts file using an Ansible playbook. My Ansible play look as below and my host file resides at /etc/ansible/hosts : - name: adding host playbook hosts: localhost connection: local tasks: - name: add host to ansible host file add_host: name: myvm.cloud.azure.com groups: mymasters Playbook executes successfully, but the new host name is not added to the Ansible hosts file. Can anybody help me on this? 回答1: add_host module does not add a host to your

how to use json file consisting of host info as input to ansible inventory

99封情书 提交于 2019-12-07 04:46:41
问题 I am trying to use the following json file as input to ansible host inventory but I get error when I run the playbook. JSON File: { "instances":{ "host": 10.66.70.33 } } Playbook: hosts: "{{ instances.host }}" remote_user: root #vars: When I run the play book I get the following errors. I am not sure where I am doing wrong. I am new to Ansible. Please advice I guess i am doing some silly mistake. [WARNING]: Could not match supplied host pattern, ignoring: all [WARNING]: provided hosts list is

Defining host as variable in Ansible hosts file

百般思念 提交于 2019-12-06 17:42:08
问题 I have a rather simple hosts file [clients] qas0062 [dbs_server] qas0063 For the users of the project we don't want them to modify hosts file but rather we have a separate user.config.yml file that contain various user-configurable parameters. There we have entry such as dbs_server: qas0065 So the question is: is it possible to use a variable in the hosts file that would use a value defined in user.config.yml ? And what would be the format? 回答1: Pretty sure you can't templatize the actual

Ansible add_host does not work, it's skipping hosts

落爺英雄遲暮 提交于 2019-12-06 08:22:31
问题 I am using Ansible to create a new EC2 instance and try to install some packages on it. The problem is I am adding a new host to a host group but I can not see that host group in another play. When it reaches "Configure EC2 instance" it says: PLAY [Configure EC2 instance] *************************************************************** skipping: no hosts matched Here is the code: --- - name: Provision an EC2 Instance hosts: localhost connection: local gather_facts: False tags: provisioning #

Ansible: How to declare global variable within playbook?

女生的网名这么多〃 提交于 2019-12-05 04:26:43
How can I declare global variable within Ansible playbook. I have searched in google and found the below solution, but its not working as expected. - hosts: all vars: prod-servers: - x.x.x.x - x.x.x.x - hosts: "{{prod-servers}}" tasks: - name: ping action: ping When I'm trying the above code, it says variable prod-servers is undefined. You cannot define a variable accessible on a playbook level (global variable) from within a play. Variable Scopes Ansible has 3 main scopes: Global: this is set by config, environment variables and the command line Play: each play and contained structures, vars

Ansible iterate over hosts in inventory group set by variable

怎甘沉沦 提交于 2019-12-04 06:48:57
问题 I have the next snippet in my role template: upstream portal { {% set nodes = groups["my_dev_cluster"] %} {% for node in nodes %} ...do something with nodes... {% endfor %} } And it works well. But when I try to parametrize inventory group name like this: upstream portal { {% set nodes = groups["{{cluster_name}}"] %} {% for node in nodes %} ...do something with nodes... {% endfor %} } I get an exception like: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable:

Where to store Ansible host file on Mac OS X

假装没事ソ 提交于 2019-12-03 00:29:28
问题 I am trying to get started with Ansible to provision my Vagrantbox, but I can’t figure out how to deal with host files. According to the documentation the should be storred in /etc/ansible/hosts , but I can’t find this on my system (Mac OS X). I also seen examples where the host.ini file situated in the document root adjacent to the vagrant file. So my question is where would you store your hostfile for setting up a single vagrant box? 回答1: While Ansible will try /etc/ansible/hosts by default

Ansible iterate over hosts in inventory group set by variable

风格不统一 提交于 2019-12-02 10:34:06
I have the next snippet in my role template: upstream portal { {% set nodes = groups["my_dev_cluster"] %} {% for node in nodes %} ...do something with nodes... {% endfor %} } And it works well. But when I try to parametrize inventory group name like this: upstream portal { {% set nodes = groups["{{cluster_name}}"] %} {% for node in nodes %} ...do something with nodes... {% endfor %} } I get an exception like: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute '{{cluster_name}}'"} Here, cluster_name - is a simple string variable

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: 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] }