How to add password variables?

77 views
Skip to first unread message

Gilberto Valentin

unread,
Mar 25, 2016, 9:54:39 AM3/25/16
to Ansible Project
I have a task that calls a root password from my vault.yml by adding it to the task as:
vars:
 ansible_become_pass
:"{{ root }}"

However, I have to use it multiple times within my tasks/main.yml. Is is possible to add that variable once to vars/main.yml

Here is what my tasks/main.yml looks like:

---
# tasks file for pb_install_test

- name: import vault file
  include_vars: "vault.yml"
  no_log: true

- name: install required nfs packages
  yum: name={{ item }} state=present
  with_items:
    - nfs-utils
    - nfs-utils-lib
    - python-pip
    - ksh

- name: create temporary pip directory
  file: path=/tmp/pip_packages state=directory mode=0755

- name: copy pip pexpect packages and dependencies
  copy: src={{ item }} dest=/tmp/pip_packages
  with_items:
    - ../../../../../files/pip_packages/pexpect-4.0.1.tar.gz
    - ../../../../../files/pip_packages/ptyprocess-0.5.1-py2.py3-none-any.whl

- name: install pexpect using pip
  command: /bin/bash -c "pip install pexpect --no-index --find-links=file:///tmp/pip_packages/"

- name: mount nfs share
  mount: name=/tmp/pb_install src="server.hostname.com:/dir/pb" fstype=nfs opts="vers=3" state=mounted

- name: install pbis and pbul
  shell: /bin/ksh "/tmp/pb_install/pbis_install" test_env

- name: join systems to domain and correct ou
  become: yes
  become_method: su
  become_user: root
  vars:
    ansible_become_pass: "{{ root }}"
  expect:
    command: /bin/bash -c "/opt/pbis/bin/domainjoin-cli join --notimesync --disable hostname --ou OU=servers,OU=linux,DC=domain,DC=host,DC=com domain.server.com join_account"
    responses:
      user@server's password: "{{ user_account }}"

- name: remove /tmp/pip_packages directory
  become: yes
  become_method: su
  become_user: root
  vars:
    ansible_become_pass: "{{ root }}"
  file: path=/tmp/pip_packages state=absent

- name: unmount nfs share
  become: yes
  become_method: su
  become_user: root
  vars:
    ansible_become_pass: "{{ root }}"
  mount: name=/tmp/pb_install src="server.hostname.com:/dir/pb" fstype=nfs state=unmounted

- name: remove nfs mount entry from fstab
  become: yes
  become_method: su
  become_user: root
  vars:
    ansible_become_pass: "{{ root }}"
  mount: name=/tmp/pb_install src="server.hostname.com:/dir/pb" fstype=nfs state=absent

Keep in mind, the above works but I have a feeling I can probably have the vars:\n ansible_become_pass: "{{ root }}" called once somewhere instead of having to add it to my tasks/main.yml

Gilberto Valentin

unread,
Mar 25, 2016, 12:09:55 PM3/25/16
to Ansible Project
OK, I figured this out. I added the following to my site.yml:

- name: install app to all test servers
  hosts: testservers
  become: yes
  user: service_account
  vars_files:
    - vault.yml
  vars:
    ansible_become_pass: "{{ root }}"

  roles:
  - pb_install_test


Reply all
Reply to author
Forward
0 new messages