ansible-playbook

Difference between become and become_user in Ansible

北城以北 提交于 2019-12-02 15:29:25
Recently I started digging into Ansible and writing my own playbooks. However, I have a troubles with understanding difference between become and become_user . As I understand it become_user is something similar to su <username> , and become means something like sudo su or "perform all commands as a sudo user". But sometimes these two directives are mixed. Could you explain the correct meaning of them? become_user defines the user which is being used for privilege escalation . become simply is a flag to either activate or deactivate the same. Here are three examples which should make it clear:

Override hosts variable of Ansible playbook from the command line

空扰寡人 提交于 2019-12-02 14:20:51
This is a fragment of a playbook that I'm using ( server.yml ): - name: Determine Remote User hosts: web gather_facts: false roles: - { role: remote-user, tags: [remote-user, always] } My hosts file has different groups of servers, e.g. [web] x.x.x.x [droplets] x.x.x.x Now I want to execute ansible-playbook -i hosts/<env> server.yml and override hosts: web from server.yml to run this playbook for [droplets] . Can I just override as a one time off thing, without editing server.yml directly? Thanks. wallydrag I don't think Ansible provides this feature, which it should. Here's something that you

Safely limiting Ansible playbooks to a single machine?

萝らか妹 提交于 2019-12-02 13:48:41
I'm using Ansible for some simple user management tasks with a small group of computers. Currently, I have my playbooks set to hosts: all and my hosts file is just a single group with all machines listed: # file: hosts [office] imac-1.local imac-2.local imac-3.local I've found myself frequently having to target a single machine. The ansible-playbook command can limit plays like this: ansible-playbook --limit imac-2.local user.yml But that seems kind of fragile, especially for a potentially destructive playbook. Leaving out the limit flag means the playbook would be run everywhere. Since these

ansible register with loop debug print not working

别等时光非礼了梦想. 提交于 2019-12-02 12:33:53
i have a simple playbook that is supposed to display my services status. and i want to view the output from the machine to see if the status is active or not. so i used a debug print, like so: - name: name_of_services shell: systemctl status {{item}} with_items: - service1 - service2 register: out - debug: var=item.stdout_lines with_items: out.results when i execute this i get a lot of info i don't want plus the item.stdout_lines info that i do want in the end of it. how is it possible to view the output of my command better? For modules, including debug, called in a loop (ie with_items), the

docker extra_host parameter expects a dictionary value for hostname, how can I use a variable?

a 夏天 提交于 2019-12-02 12:04:16
In ansible playbook docker parameter extra_host takes two parts host: ip_address. I am trying to pass the host and ipaddress in as variables. They are from prompt vars. The end result in my hosts file is: 1.2.3.4 {{server_hostname}}. Here is the code: vars_prompt: - name: "server_ip" prompt: "Please enter the server IP address" private: no - name: "server_hostname" prompt: "Please enter the server hostname" private: no tasks: - name: Install Tomcat docker: image: tomcat:8.0 pull: missing name: tomcat state: restarted ports: - "8080:8080" - "443:443" extra_hosts: "{{server_hostname}}": "{

Ansible: extract archive to user's dir

元气小坏坏 提交于 2019-12-02 09:12:31
I'm trying to build an ansible playbook which extracts an archive (available through http) under a folder to be created in the user's home directory. So far I've come up with: - name: Extract archive unarchive: creates: wildfly src: "http://download.jboss.org/wildfly/10.1.0.Final/wildfly-10.1.0.Final.zip" dest: "{{ ansible_user_dir }}"/wildfly remote_src: yes However by running it, I get a syntax error: here is the offending line: dest: "{{ ansible_user_dir }}"/wildfly ^ here I've tried also without quotes, but the issue stays the same. By hardcoding the user's home dir it works- except that

How to create dynamic list in yaml?

别来无恙 提交于 2019-12-02 08:25:31
问题 I am trying to render a template. I have to create a list as host: - '111.222.333.444' - '555.666.777.888' which has to be taken from another host file. I am using something like this: {% for host in groups['hostgroup'] %} host: {{ host }} {% endfor %} What is the correct way to achieve the result? 回答1: Assuming you wish to declare a variable in your inventory called host which contains a list of ip addresses, you can try: host: {{ groups['hostgroup'] }} Or you could skip declaring this

How to register a var in either one or another task

青春壹個敷衍的年華 提交于 2019-12-02 08:23:31
This task collection doesn't work as I hoped it would: - name: Find out whether syslog-ng is installed (yum) tags: syslog_forwarding command: yum -q list installed syslog-ng register: syslog_ng_check failed_when: False changed_when: False when: ansible_pkg_mgr == 'yum' - name: Find out whether syslog-ng is installed (apt) tags: syslog_forwarding command: dpkg -s syslog-ng register: syslog_ng_check failed_when: False changed_when: False when: ansible_pkg_mgr == 'apt' - name: Configure syslog-ng to forward all logs to syslog servers (apt) tags: syslog_forwarding template: src: syslog_ng_forward

How to create dynamic list in yaml?

一曲冷凌霜 提交于 2019-12-02 06:43:48
I am trying to render a template. I have to create a list as host: - '111.222.333.444' - '555.666.777.888' which has to be taken from another host file. I am using something like this: {% for host in groups['hostgroup'] %} host: {{ host }} {% endfor %} What is the correct way to achieve the result? Zasz Assuming you wish to declare a variable in your inventory called host which contains a list of ip addresses, you can try: host: {{ groups['hostgroup'] }} Or you could skip declaring this variable and use {{ groups['hostgroup'] }} directly wherever you plan to use {{ host }} Look at add-quotes

Add binaries to PATH with Ansible

自作多情 提交于 2019-12-02 04:23:45
问题 I'm trying to install the Kiex Version manager for the Elixir programming language using Ansible. These are the plays I use for this: - name: Kiex Installation hosts: web gather_facts: false remote_user: deployer tasks: - shell: \curl -sSL https://raw.githubusercontent.com/taylor/kiex/master/install | bash -s - name: Add Kiex Bin to Path lineinfile: dest: /home/deployer/.bashrc regexp: '^test -s' line: '[[ -s "$HOME/.kiex/scripts/kiex" ]] && source "$HOME/.kiex/scripts/kiex"' - name: Reload