ansible-playbook

Sourcing a file before executing commands in Ansible

一笑奈何 提交于 2019-11-29 06:20:34
I am trying to install node js version using nvm using below Ansible yml file. I get error like source "source /home/centos/.nvm/nvm.sh" file not found. But if I do the same by logging into the machine using ssh then it works fine. - name: Install nvm git: repo=https://github.com/creationix/nvm.git dest=~/.nvm version={{ nvm.version }} tags: nvm - name: Source nvm in ~/.profile lineinfile: > dest=~/.profile line="source ~/.nvm/nvm.sh" create=yes tags: nvm - name: Install node {{ nvm.node_version }} command: "{{ item }}" with_items: - "source /home/centos/.nvm/nvm.sh" - nvm install {{ nvm.node

Running an Ansible Playbook on a particular group of servers

a 夏天 提交于 2019-11-29 04:49:17
问题 I have the following /etc/ansible/hosts: [ESNodes] isk-vsrv643 isk-vsrv644 isk-vsrv645 [PerfSetup] isk-dsrv613 isk-dsrv614 I know there is an option to run a playbook on particular hosts with -l Is there a way to run a playbook only on the PerfSetup group? 回答1: Same way as you would do for hosts : -l PerfSetup 来源: https://stackoverflow.com/questions/22129422/running-an-ansible-playbook-on-a-particular-group-of-servers

using regex in jinja 2 for ansible playbooks

一曲冷凌霜 提交于 2019-11-29 03:46:47
HI i am new to jinja2 and trying to use regular expression as shown below {% if ansible_hostname == 'uat' %} {% set server = 'thinkingmonster.com' %} {% else %} {% set server = 'define yourself' %} {% endif %} {% if {{ server }} match('*thinking*') %} {% set ssl_certificate = 'akash' %} {% elif {{ server }} match( '*sleeping*')%} {% set ssl_certificate = 'akashthakur' %} {% endif %} based on the value of "server" i would like to evaluate as which certificates to use. ie if domain contains "thinking" keyword then use these certificates and if it contains "sleeping" keyword then use that

Ansible: Insert line if not exists

断了今生、忘了曾经 提交于 2019-11-29 02:02:31
问题 I'm trying insert a line in a property file using ansible. I want to add some property if it does not exist, but not replace it if such property already exists in the file. I add to my ansible role - name: add couchbase host to properties lineinfile: dest=/database.properties regexp="^couchbase.host" line="couchbase.host=127.0.0.1" But this replaces the property value back to 127.0.0.1 if it exists already in the file. What I'm doing wrong? 回答1: The lineinfile module does what it's supposed

ansible wget then exec scripts => get_url equivalent

独自空忆成欢 提交于 2019-11-29 01:18:04
I always wonder what is the good way to replace the following shell tasks using the "ansible way" (with get_url , etc.): - name: Install oh-my-zsh shell: wget -qO - https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash - or - name: Install nodesource repo shell: curl -sL https://deb.nodesource.com/setup_5.x | bash - RaviTezu This worked for me: - name: Download zsh installer get_url: url=https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh dest=/tmp/zsh-installer.sh - name: Execute the zsh-installer.sh shell: /tmp/zsh-installer.sh - name: Remove the zsh

Pass array in --extra-vars - Ansible

若如初见. 提交于 2019-11-29 00:18:29
问题 How can I pass yaml array to --extra-vars in Ansible playbook. Ansible documentation does not declares its syntax nor I can find that on any internet resource. I mean if I have a playbook: --- - hosts: {{hostName}} - remote_user: admin ... Then I should call my playbook like ansible-playbook DeployWar.yml --extra-vars="hostName=tomcat-webApp" But I want to run this playbook on two servers say tomcat-webApp and tomcat-all , and I want to control it from out side i.e. using --extra-vars . What

Ansible remote_user vs ansible_user

旧巷老猫 提交于 2019-11-28 22:53:00
The question is simple: what is the difference between ansible_user (former ansible_ssh_user ) and remote_user in Ansible, besides that the first one is set if configuration file and the latter one is set in plays / roles? How do they relate to -u / --user command line options? slayedbylucifer They both seem to be the same. Take a look here: https://github.com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55 # the magic variable mapping dictionary below is used to translate # host/inventory variables to fields in the PlayContext # object. The dictionary values are

How can I check if file has been downloaded in ansible

房东的猫 提交于 2019-11-28 18:17:42
I am downloading the file with wget from ansible. - name: Download Solr shell: chdir={{project_root}}/solr wget http://mirror.mel.bkb.net.au/pub/apache/lucene/solr/4.7.0/solr-4.7.0.zip but I only want to do that if zip file does not exist in that location. Currently the system is downloading it every time. DomaNitro Unless you have a reason to use wget why not use get_url module. It will check if the file needs to be downloaded. --- - hosts : all gather_facts : no tasks: - get_url: url="http://mirror.mel.bkb.net.au/pub/apache/lucene/solr/4.7.0/solr-4.7.0.zip" dest="{{project_root}}/solr-4.7.0

ansible ssh prompt known_hosts issue

﹥>﹥吖頭↗ 提交于 2019-11-28 17:24:44
问题 I'm running Ansible playbook and it works fine on one machine. On a new machine when I try for the first time, I get the following error. 17:04:34 PLAY [appservers] ************************************************************* 17:04:34 17:04:34 GATHERING FACTS *************************************************************** 17:04:34 fatal: [server02.cit.product-ref.dev] => {'msg': "FAILED: (22, 'Invalid argument')", 'failed': True} 17:04:34 fatal: [server01.cit.product-ref.dev] => {'msg':

How to assign an array to a variable in an Ansible-Playbook

我与影子孤独终老i 提交于 2019-11-28 16:51:49
问题 In a playbook I got the following code: --- - hosts: db vars: postgresql_ext_install_contrib: yes postgresql_pg_hba_passwd_hosts: ['10.129.181.241/32'] ... I would like to replace the value of postgresql_pg_hba_passwd_hosts with all of my webservers private ips . I understand I can get the values like this in a template : {% for host in groups['web'] %} {{ hostvars[host]['ansible_eth1']['ipv4']['address'] }} {% endfor %} What is the simplest/easiest way to assign the result of this loop to a