[ansible-project] Extra var does not override host_vars when passing to include

2016-10-15 Thread Do Hoang Khiem
Enter code here...
When I pass a variable to include: statement, using value from extra vars, 
the value inside the included task file is still the value from host_vars, 
not extra vars (while extra vars are considered as highest precedence)

Here'e an example

*main.yml*


- name: test extra var
  hosts: localhost
connection: local
  gather_facts: no

  tasks:
- include: task.yml internal_var={{my_var}}



*task.yml*

- name: print internal_var

  debug: msg="hello, {{internal_var}}"


*inventory*
[local]

localhost ansible_connection=local


*host_vars/localhost*
my_var: I am from host_vars

then test



LAZ-VN-L-M-1034:test user$ ansible-playbook -i inventory main.yml -e 
'my_var=testtest'

PLAY [pulling Avanan Registration Management UI from git remote repository] 
*** 

TASK: [print internal_var] 
 
ok: [localhost] => {
"msg": "hello, I am from host_vars"
}

PLAY RECAP 
 
localhost  : ok=1changed=0unreachable=0failed=0 
  

 


It still takes value from host_vars/localhost even though extra var is 
passed.


Is it an error? Ansible version is  1.9.4


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6670789a-e4b2-4fe0-a662-a3d4f96ac3c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] host_vars/all does not work anymore?

2016-07-21 Thread Do Hoang Khiem
My simple test case:


*ubuntu@ansible-tower-server:~/temp/ansible$ ansible --version*

ansible 1.9.4

  configured module search path = None


*ubuntu@ansible-tower-server:~/temp/ansible$ tree .*

*.*

├── *env*

│   └── *staging*

│   └── *th*

│   ├── hosts

│   └── *host_vars*

│   └── all

├── *host_vars*

│   └── all

└── test_host_vars.yml


*ubuntu@ansible-tower-server:~/temp/ansible$ cat test_host_vars.yml *

- hosts: all

  gather_facts: yes


  tasks:

- debug: msg="var1={{var1}} var2={{var2}}"


*ubuntu@ansible-tower-server:~/temp/ansible$ cat env/staging/th/hosts*

localhost


*ubuntu@ansible-tower-server:~/temp/ansible$ cat 
env/staging/th/host_vars/all *

# variables for all th staging hosts


var1: value1

var2: value2


*ubuntu@ansible-tower-server:~/temp/ansible$ ansible-playbook -i 
env/staging/th/hosts test_host_vars.yml *


PLAY [all] 
 


GATHERING FACTS 
*** 

ok: [localhost]


TASK: [debug msg="var1={{var1}} venture={{venture}} nr_key={{nr_key}} 
timezone={{timezone}}"] *** 

fatal: [localhost] => One or more undefined variables: 'var1' is undefined


FATAL: all hosts have already failed -- aborting


PLAY RECAP 
 

   to retry, use: --limit @/home/ubuntu/test_host_vars.retry


localhost  : ok=1changed=0unreachable=1
failed=0   


So from what I see, host_vars/all does not work even if it's located at 
same directory as playbook or same directory as inventory.


>From Ansible: http://docs.ansible.com/ansible/intro_inventory.html


*Tip: In Ansible 1.2 or later the group_vars/ and host_vars/ directories 
can exist in the playbook directory OR the inventory directory. If both 
paths exist, variables in the playbook directory will override variables 
set in the inventory directory.*


Is it correct anymore or am I wrong somewhere?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/04008fe7-c479-4acf-aec4-2d9175176f6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible Tower: sudo task on localhost job failed

2015-07-28 Thread Do Hoang Khiem
Updated on this:

This problem occurred if I set connection: local in playbook, I often use 
it when running local playbook from command line, if remove that line the 
playbook runs successfully from Ansible Tower.

So question: Doesn't Ansible Tower run playbook with 'local' connection? As 
in the case run local playbook from Ansible Tower I still need to provide 
credentials.


On Wednesday, 29 July 2015 11:18:43 UTC+7, Do Hoang Khiem wrote:
>
> I've deployed an instance of Ansible Tower (using official Ansible EC2 
> AMI) on one of our server. There're some of our playbooks that always run 
> locally (so, hosts = localhost, connection = local). Normally those 
> playbooks run fine when run with ansible-playbook from command line but I 
> always got this error when run the same playbook from Ansible Tower job
>
> failed: [localhost] => (item=git,ruby,npm,nodejs-legacy) => {"failed": 
> true, "item": "git,ruby,npm,nodejs-legacy", "parsed": false} sudo: 
> effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' 
> option set or an NFS file system without root privileges?
>
> the task is a simple apt
>
> - name: "ensure required packages: git, ruby, npm and nodejs-legacy are 
> installed"
>   apt: pkg={{item}} state=installed force=yes
>   with_items:
> - git
> - ruby
> - npm
> - nodejs-legacy
>   sudo: yes
>
> Another thing I don't know is whether run playbook from Ansible Tower with 
> connection=local like with ansible-playbook? As with ansible-playbook when 
> running on localhost and connection=local I don't need credentials while 
> with Ansible Tower currently I have to provide credentials (SSH key) for 
> localhost access. 
>
> Thanks  in advance for any comments!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ba9c79d4-4735-48bd-9053-05dc849c2f13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible Tower: sudo task on localhost job failed

2015-07-28 Thread Do Hoang Khiem
I've deployed an instance of Ansible Tower (using official Ansible EC2 AMI) 
on one of our server. There're some of our playbooks that always run 
locally (so, hosts = localhost, connection = local). Normally those 
playbooks run fine when run with ansible-playbook from command line but I 
always got this error when run the same playbook from Ansible Tower job

failed: [localhost] => (item=git,ruby,npm,nodejs-legacy) => {"failed": 
true, "item": "git,ruby,npm,nodejs-legacy", "parsed": false} sudo: 
effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' 
option set or an NFS file system without root privileges?

the task is a simple apt

- name: "ensure required packages: git, ruby, npm and nodejs-legacy are 
installed"
  apt: pkg={{item}} state=installed force=yes
  with_items:
- git
- ruby
- npm
- nodejs-legacy
  sudo: yes

Another thing I don't know is whether run playbook from Ansible Tower with 
connection=local like with ansible-playbook? As with ansible-playbook when 
running on localhost and connection=local I don't need credentials while 
with Ansible Tower currently I have to provide credentials (SSH key) for 
localhost access. 

Thanks  in advance for any comments!

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5f180239-012d-4a72-b1c3-399e07e3543e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Any way to specify SSH key file for EC2 host using EC2 inventory

2015-05-30 Thread Do Hoang Khiem
I'm using Ansible to manage multiple EC2 instance that could be launched 
dynamically, keypair is generated for each instance then store in local 
machine. 

Previously I use default inventory file and in Ansible I can use lineinfile 
module to add new EC2 host to hosts file with additional vars like 
ansible_ssh_user, ansible_ssh_private_key_file, that's very convenient as 
each time I run Ansible playbook I dont have to explicitly specify SSH key. 

But now with change to use EC2 inventory, I can't find a way to add such 
kind of vars to EC2 host, I know using ssh-agent is a solution, but I would 
look for a more explicit method that I can manage keys better than just add 
every generated key to ssh-agent.

Any suggestions? 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f02e66be-f40e-4b7a-b10a-b51706532e55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: "gem" module reports gem as present when it is not and therefore will not install

2015-05-25 Thread Do Hoang Khiem
I had exactly the same problem when running on VirtualBox VM (Ubuntu 14.4, 
Ansible 1.9)

vagrant@localhost:~$ sudo gem list


*** LOCAL GEMS ***


vagrant@localhost:~$ gem list


*** LOCAL GEMS ***


vagrant@localhost:~$ ansible localhost -m gem -a "name=sass state=latest 
include_dependencies=yes user_install=no" --sudo
localhost | success >> {
"changed": false, 
"name": "sass", 
"state": "latest", 
"version": "3.4.14"
}


vagrant@localhost:~$ sudo gem list


*** LOCAL GEMS ***


vagrant@localhost:~$ gem list


*** LOCAL GEMS ***



While it works when I ran on my real machine

khiem@khiem-SVS13123CVW ~/ansible/avanan $ ansible localhost -m gem -a 
"name=sass 
state=present user_install=no" --sudo -K
SUDO password: 
localhost | success >> {
"changed": true,
"name": "sass",
"state": "present"
}


khiem@khiem-SVS13123CVW ~/ansible/avanan $ gem list


*** LOCAL GEMS ***


sass (3.4.14)

I endup temporarily switch to use shelll command: gem install sass, losing 
idempotence :(

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/363952c9-55bd-4b88-aebe-b63c77d89f53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.