ansible-playbook

Ansible - with_dict: dictionary - How to use variables defined in each dictionary which depends upon others

。_饼干妹妹 提交于 2019-12-05 10:29:39
Environment is: Ansible 1.9.2, CentOS 6.5 I have created a role to download JAVA (.tar.gz) artifact files for 3 different JAVA versions from Artifactory. I'm trying to use Ansible's with_dict feature (instead of using with_items). Created the following files: $ cat roles/java/defaults/main.yml --- java_versions: java7_60: version: 1.7.60 group_path: com/oracle/jdk classifier: linux-x64 ext: tar.gz dist_file: "jdk-{{ version }}-{{ classifier }}-{{ ext }}" # dist_file: "jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}" dist_url: "{{ artifactory_url }}/{{ group_path }}

Running Oracle SQL scripts with Ansible playbook

泪湿孤枕 提交于 2019-12-05 10:02:00
A look at the core database modules in Ansible documentation shows no signs of a module for Oracle. What is the best way to handle SQL/PLSQL deployments via Ansible for Oracle databases? Are we expected to use roles from Ansible Galaxy to handle this? Very few people seem to have downloaded roles listed on Galaxy for Oracle. I have created a role to install apex 5 (where I first uninstall apex 4). I use modules like 'script' and 'shell'. I am not too happy about environment initialization but I am still learning. For any SQL/PLSQL task, sqlplus is the right tool. (perhaps SQLcl can do better..

Pass Ansible variables from one role (running on one host) to another role running on another host within the same playbook

孤人 提交于 2019-12-05 03:13:10
I have a playbook that runs different roles on different hosts. Is it possible to pass a variable from one role running on one host to another role on another host running within the same playbook run? Or any workaround ? playbook host1 role1 here I get some variables: var1 var2 ...etc host2 role2 here I need to use var1 var2 ... etc from the above host/role The task in role1 that sets teh variable db looks like this: - shell: cd /ACE/conf && grep ^db.url local1.properties | awk -F/ '{print $4}' | awk -F? '{print $1}' register: db UPDATE: On the first host the values are dynamic, it's like a

Ansible: how to clone a repository as other user

北城以北 提交于 2019-12-05 03:12:26
I'm trying to write deployments rules with Ansible. Some of the steps are: Update and Upgrade Server Create a user called harry Add Public and Private keys to harry Clone a Git Repository from bitbucket.org I want to clone the repository as harry user in his home directory (that's why I'm copying it's public and private keys). The issue is that it is not possible to specifiy a user the git clone must be executed as. So Ansible try to clone the repository as root and failed because he doesn't have rights to access the repository. How do you solve this ? As per Ansible's documentation on

Getting the IP address/attributes of the AWS instance created using Ansible

こ雲淡風輕ζ 提交于 2019-12-05 03:08:58
I know how to create an AWS instance using Ansible. Now what I want to achieve is to configure that instance as web server by installing nginx using the same playbook which created the instance. The goal of the playbook will be: Create an AWS instance. Configure the instance as Web server by setting up the Nginx server. Is it possible with ansible? Read http://www.ansible.com/blog/ansible-ec2-tags It details how to spin up an ec2 instance (or multiple) and then run tasks against it (I.e install nginx). I'f you want to jump straight to the example playbook https://github.com/chrismeyersfsu

how to create Ansible playbook to obtain OS versions of the remote hosts?

99封情书 提交于 2019-12-05 02:51:33
I'm new to ansible. I have a requirement that requires me to pull OS version for of more than 450 linux severs hosted in AWS. AWS does not provide this feature - it rather suggests us to get it from puppet or chef. I created few simple playbooks which does not run --- - hosts: testmachine user: ec2-user sudo: yes tasks: - name: Update all packages to latest yum: name=* state=latest task: - name: obtain OS version shell: Redhat-release playbook should output a text file with hostname and OS version. Any insight on this will be highly appreciated. Use one of the following Jinja2 expressions: {{

How to pass variables from one role downstream to other dependency roles with ansible?

北城余情 提交于 2019-12-05 01:24:13
I have a generic webserver role that is using another nginx role to spawn new vservers. webserver/meta/main.yml looks like: allow_duplicates: yes dependencies: - role: nginx name: api vserver frontend_port: "{{ frontend_port }}" domain: "{{ api_domain }}" backend_host: 127.0.0.1 - role: nginx name: portal vserver domain: "{{ portal_domain }}" backend_host: 127.0.0.1 The problem is that these variables are supposed to be defined inside the webserver-role/vars/(test|staging).yml Is seems that Ansible will try to load the dependencies before loading the variables. How can I solve this problem? I

Is it possible to use Ansible authorized_key exclusive with multiple keys?

雨燕双飞 提交于 2019-12-05 00:42:39
I'm fairly new in using Ansible and have been reading here and google and haven't found an answer yet. My scenario is that I have 1 user on a server but 2-3 different pub keys that need to put in it's authorized_keys file. I can successfully remove all keys, or add all keys with this script: --- - hosts: all tasks: - name: update SSH keys authorized_key: user: <user> key: "{{ lookup('file', item) }}" state: present #exclusive: yes with_fileglob: - ../files/pub_keys/*.pub With the present flag it reads and adds all the keys. With the absent flag it removes all keys listed. Problem is that I

Accessing remote_user variable

人走茶凉 提交于 2019-12-04 23:56:05
This seems to work, but is it fragile? I want the owner and group in the files command to be set to someguy . I'd expect to be able to use {{ remote_user }} but that doesn't work. This is an example playbook showing what I mean. --- - hosts: foobar remote_user: someguy tasks: - name: configure /usr/src/foo file: dest: /usr/src/foo state: directory owner: {{ ansible_ssh_user }} group: {{ ansible_ssh_user }} recurse: yes sudo: yes This doesn't work: --- - hosts: foobar remote_user: someguy tasks: - name: configure /usr/src/foo file: dest: /usr/src/foo state: directory owner: {{ remote_user }}

ansible: Is there something like with_fileglobs for files on remote machine?

☆樱花仙子☆ 提交于 2019-12-04 22:41:37
I'm trying to turn these lines into something I can put in an ansible playbook: # Install Prezto files shopt -s extglob shopt -s nullglob files=( "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/!(README.md) ) for rcfile in "${files[@]}"; do [[ -f $rcfile ]] && ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile##*/}" done So far I've got the following: - name: Link Prezto files file: src={{ item }} dest=~ state=link with_fileglob: - ~/.zprezto/runcoms/z* I know it isn't the same, but it would select the same files: except with_fileglob looks on the host machine, and I want it to look on the remote machine. Is